App-manwrap-pm
view release on metacpan or search on metacpan
script/manwrap-pm view on Meta::CPAN
#!perl
# NO_PERINCI_CMDLINE_SCRIPT
# FRAGMENT id=shcompgen-hint completer=1 for=man
use 5.010001;
use strict;
use warnings;
use Log::ger;
use Complete::File qw(complete_file);
use Complete::Util qw(complete_array_elem complete_comma_sep);
use Getopt::Long::Complete qw(GetOptionsWithCompletion);
our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
our $DATE = '2023-01-17'; # DATE
our $DIST = 'App-manwrap-pm'; # DIST
our $VERSION = '0.006'; # VERSION
my $opts = {
};
my $noop = sub {};
my $has_arg;
my $comp_man_or_mod = sub {
require Complete::Man;
require Complete::Module;
require Complete::Util;
my %args = @_;
my $word = $args{word};
# XXX for more proper
my $has_arg = 0;
for (0..$#{ $args{words} }) {
if ($_ ne $args{argpos} && /^[^-]/) {
$has_arg++;
last;
}
}
my @answers;
if ($word =~ m!/!) {
push @answers, Complete::Module::complete_module(word=>$word);
} elsif ($word !~ /^-/ && !$has_arg) {
push @answers, Complete::Man::complete_manpage(word=>$word, use_mandb=>0);
}
Complete::Util::combine_answers(@answers);
};
my @orig_argv = @ARGV;
# this is taken from App::cpanminus::script and should be updated from time to
# time.
GetOptionsWithCompletion(
sub {
my %args = @_;
my $type = $args{type};
my $word = $args{word};
if ($word eq '') {
return {message=>"Gathering list of all modules and manpages will take at least a few seconds. Please type something first."};
} elsif ($type eq 'arg') {
log_trace("[manwrap-pm] Completing arg");
return $comp_man_or_mod->(%args);
} elsif ($type eq 'optval') {
my $ospec = $args{ospec};
my $opt = $args{opt};
log_trace("[manwrap-pm] Completing optval (opt=$opt, ospec=$ospec)");
if ($ospec eq 'config-file|C=s') {
return complete_file(filter=>'f', word=>$word);
} elsif ($ospec eq 'locale|L=s') {
require Complete::Locale;
return Complete::Locale::complete_locale(word => $word);
} elsif ($ospec eq 'manpath|M=s') {
return complete_file(filter=>'d', word=>$word);
} elsif ($ospec eq 'sections|S|s=s') {
require Complete::Man;
my $ss = Complete::Man::complete_manpage_section(word=>'');
my $ss_elems = [];
my $ss_summaries = [];
for (@$ss) {
if (ref $_ eq 'HASH') {
push @$ss_elems, $_->{word};
push @$ss_summaries, $_->{summary};
} else {
push @$ss_elems, $_;
push @$ss_summaries, '';
}
}
log_trace "elems: %s", $ss_elems;
log_trace "summaries: %s", $ss_summaries;
return complete_comma_sep(word=>$word, elems=>$ss_elems, summaries=>$ss_summaries, uniq=>1);
} elsif ($ospec eq 'pager|P=s') {
require Complete::Program;
return Complete::Program::complete_program(word=>$word);
}
}
return [];
},
'config-file|C=s' => $noop,
'debug|d' => $noop,
'default|D' => $noop,
'warnings=s' => $noop,
'whatis|f' => $noop,
'apropos|k' => $noop,
'global-apropos|K' => $noop,
'local-file|l' => $noop,
'where|path|location|w' => $noop,
'where-cat|location-cat|W' => $noop,
'catman|c' => $noop,
'recode|R=s' => $noop,
'locale|L=s' => $noop,
( run in 0.780 second using v1.01-cache-2.11-cpan-99c4e6809bf )