App-genpw-base58
view release on metacpan or search on metacpan
script/_genpw-base58 view on Meta::CPAN
# v => 1.1,
# summary => 'Completion routines for bash shell',
#};
#
#sub _expand_tilde {
# my ($user, $slash) = @_;
# my @ent;
# if (length $user) {
# @ent = getpwnam($user);
# } else {
# @ent = getpwuid($>);
# $user = $ent[0];
# }
# return $ent[7] . $slash if @ent;
# "~$user$slash";
#}
#
#sub _add_unquoted {
# no warnings 'uninitialized';
#
# my ($word, $is_cur_word, $after_ws) = @_;
#
#
# $word =~ s!^(~)(\w*)(/|\z) | # 1) tilde 2) username 3) optional slash
# \\(.) | # 4) escaped char
# \$(\w+) # 5) variable name
# !
# $1 ? (not($after_ws) || $is_cur_word ? "$1$2$3" : _expand_tilde($2, $3)) :
# $4 ? $4 :
# ($is_cur_word ? "\$$5" : $ENV{$5})
# !egx;
# $word;
#}
#
#sub _add_double_quoted {
# no warnings 'uninitialized';
#
# my ($word, $is_cur_word) = @_;
#
# $word =~ s!\\(.) | # 1) escaped char
# \$(\w+) # 2) variable name
# !
# $1 ? $1 :
# ($is_cur_word ? "\$$2" : $ENV{$2})
# !egx;
# $word;
#}
#
#sub _add_single_quoted {
# my $word = shift;
# $word =~ s/\\(.)/$1/g;
# $word;
#}
#
#$SPEC{point} = {
# v => 1.1,
# summary => 'Return line with point marked by a marker',
# description => <<'_',
#
#This is a utility function useful for testing/debugging. `parse_cmdline()`
#expects a command-line and a cursor position (`$line`, `$point`). This routine
#expects `$line` with a marker character (by default it's the caret, `^`) and
#return (`$line`, `$point`) to feed to `parse_cmdline()`.
#
#Example:
#
# point("^foo") # => ("foo", 0)
# point("fo^o") # => ("foo", 2)
#
#_
# args_as => 'array',
# args => {
# cmdline => {
# summary => 'Command-line which contains a marker character',
# schema => 'str*',
# pos => 0,
# },
# marker => {
# summary => 'Marker character',
# schema => ['str*', len=>1],
# default => '^',
# pos => 1,
# },
# },
# result_naked => 1,
#};
#sub point {
# my ($line, $marker) = @_;
# $marker //= '^';
#
# my $point = index($line, $marker);
# die "BUG: No marker '$marker' in line <$line>" unless $point >= 0;
# $line =~ s/\Q$marker\E//;
# ($line, $point);
#}
#
#$SPEC{parse_cmdline} = {
# v => 1.1,
# summary => 'Parse shell command-line for processing by completion routines',
# description => <<'_',
#
#This function basically converts `COMP_LINE` (str) and `COMP_POINT` (int) into
#something like (but not exactly the same as) `COMP_WORDS` (array) and
#`COMP_CWORD` (int) that bash supplies to shell functions.
#
#The differences with bash are (these differences are mostly for parsing
#convenience for programs that use this routine; this comparison is made against
#bash versions 4.2-4.3):
#
#1) quotes and backslashes are stripped (bash's `COMP_WORDS` contains all the
# quotes and backslashes);
#
#2) quoted phrase that contains spaces, or phrase that contains escaped spaces is
# parsed as a single word. For example:
#
# command "First argument" Second\ argument
#
# bash would split it as (represented as Perl):
#
# ["command", "\"First", "argument\"", "Second\\", "argument"]
#
script/_genpw-base58 view on Meta::CPAN
# then the parse result will be:
#
# ["command", "--foo", "=", "bar", "http", ":", "//example.com", ":", "80", "Foo", "::", "Bar"]
#
# which is annoying sometimes. But we follow bash here so we can more easily
# accept input from a joined `COMP_WORDS` if we write completion bash functions,
# e.g. (in the example, `foo` is a Perl script):
#
# _foo ()
# {
# local words=(${COMP_CWORDS[@]})
# # add things to words, etc
# local point=... # calculate the new point
# COMPREPLY=( `COMP_LINE="foo ${words[@]}" COMP_POINT=$point foo` )
# }
#
# To avoid these word-breaking characters to be split/grouped, we can escape
# them with backslash or quote them, e.g.:
#
# command "http://example.com:80" Foo\:\:Bar
#
# which bash will parse as:
#
# ["command", "\"http://example.com:80\"", "Foo\\:\\:Bar"]
#
# and we parse as:
#
# ["command", "http://example.com:80", "Foo::Bar"]
#
#* Due to the way bash parses the command line (see above), the two below are
# equivalent:
#
# % cmd --foo=bar
# % cmd --foo = bar
#
#Because they both expand to `['--foo', '=', 'bar']`. But obviously
#<pm:Getopt::Long> does not regard the two as equivalent.
#
#_
# args_as => 'array',
# args => {
# cmdline => {
# summary => 'Command-line, defaults to COMP_LINE environment',
# schema => 'str*',
# pos => 0,
# },
# point => {
# summary => 'Point/position to complete in command-line, '.
# 'defaults to COMP_POINT',
# schema => 'int*',
# pos => 1,
# },
# opts => {
# summary => 'Options',
# schema => 'hash*',
# description => <<'_',
#
#Optional. Known options:
#
#* `truncate_current_word` (bool). If set to 1, will truncate current word to the
# position of cursor, for example (`^` marks the position of cursor):
# `--vers^oo` to `--vers` instead of `--versoo`. This is more convenient when
# doing tab completion.
#
#_
# schema => 'hash*',
# pos => 2,
# },
# },
# result => {
# schema => ['array*', len=>2],
# description => <<'_',
#
#Return a 2-element array: `[$words, $cword]`. `$words` is array of str,
#equivalent to `COMP_WORDS` provided by bash to shell functions. `$cword` is an
#integer, roughly equivalent to `COMP_CWORD` provided by bash to shell functions.
#The word to be completed is at `$words->[$cword]`.
#
#Note that COMP_LINE includes the command name. If you want the command-line
#arguments only (like in `@ARGV`), you need to strip the first element from
#`$words` and reduce `$cword` by 1.
#
#
#_
# },
# result_naked => 1,
# links => [
# ],
#};
#sub parse_cmdline {
# no warnings 'uninitialized';
# my ($line, $point, $opts) = @_;
#
# $line //= $ENV{COMP_LINE};
# $point //= $ENV{COMP_POINT} // 0;
#
# die "$0: COMP_LINE not set, make sure this script is run under ".
# "bash completion (e.g. through complete -C)\n" unless defined $line;
#
#
# my @words;
# my $cword;
# my $pos = 0;
# my $pos_min_ws = 0;
# my $after_ws = 1;
# my $chunk;
# my $add_blank;
# my $is_cur_word;
# $line =~ s!( # 1) everything
# (")((?: \\\\|\\"|[^"])*)(?:"|\z)(\s*) | # 2) open " 3) content 4) space after
# (')((?: \\\\|\\'|[^'])*)(?:'|\z)(\s*) | # 5) open ' 6) content 7) space after
# ((?: \\\\|\\"|\\'|\\=|\\\s|[^"'@><=|&\(:\s])+)(\s*) | # 8) unquoted word 9) space after
# ([\@><=|&\(:]+) | # 10) non-whitespace word-breaking characters
# \s+
# )!
# $pos += length($1);
# #say "D: \$1=<$1> \$2=<$3> \$3=<$3> \$4=<$4> \$5=<$5> \$6=<$6> \$7=<$7> \$8=<$8> \$9=<$9> \$10=<$10>";
# #say "D:<$1> pos=$pos, point=$point, cword=$cword, after_ws=$after_ws";
#
# if ($2 || $5 || defined($8)) {
# # double-quoted/single-quoted/unquoted chunk
script/_genpw-base58 view on Meta::CPAN
# my $word = $args{word};
# my $ospec = $args{ospec};
# if ($ospec && $ospec eq 'format=s') {
# complete_array_elem(array=>[qw/json text xml yaml/], word=>$word);
# } else {
# complete_user(word=>$word);
# }
# },
# );
#
#_
# },
# words => {
# summary => 'Command line arguments, like @ARGV',
# description => <<'_',
#
#See function `parse_cmdline` in <pm:Complete::Bash> on how to produce this (if
#you're using bash).
#
#_
# schema => 'array*',
# req => 1,
# },
# cword => {
# summary =>
# "Index in words of the word we're trying to complete",
# description => <<'_',
#
#See function `parse_cmdline` in <pm:Complete::Bash> on how to produce this (if
#you're using bash).
#
#_
# schema => 'int*',
# req => 1,
# },
# extras => {
# summary => 'Add extra arguments to completion routine',
# schema => 'hash',
# description => <<'_',
#
#The keys from this `extras` hash will be merged into the final `%args` passed to
#completion routines. Note that standard keys like `type`, `word`, and so on as
#described in the function description will not be overwritten by this.
#
#_
# },
# bundling => {
# schema => 'bool*',
# default => 1,
# 'summary.alt.bool.not' => 'Turn off bundling',
# description => <<'_',
#
#If you turn off bundling, completion of short-letter options won't support
#bundling (e.g. `-b<tab>` won't add more single-letter options), but single-dash
#multiletter options can be recognized. Currently only those specified with a
#single dash will be completed. For example if you have `-foo=s` in your option
#specification, `-f<tab>` can complete it.
#
#This can be used to complete old-style programs, e.g. emacs which has options
#like `-nw`, `-nbc` etc (but also have double-dash options like
#`--no-window-system` or `--no-blinking-cursor`).
#
#_
# },
# },
# result_naked => 1,
# result => {
# schema => ['any*' => of => ['hash*', 'array*']],
# description => <<'_',
#
#You can use `format_completion` function in <pm:Complete::Bash> module to format
#the result of this function for bash.
#
#_
# },
#};
#sub complete_cli_arg {
# require Complete::Util;
# require Getopt::Long::Util;
#
# my %args = @_;
#
# my $fname = __PACKAGE__ . "::complete_cli_arg";
# my $fres;
#
# $args{words} or die "Please specify words";
# my @words = @{ $args{words} };
# defined(my $cword = $args{cword}) or die "Please specify cword";
# my $gospec = $args{getopt_spec} or die "Please specify getopt_spec";
# my $comp = $args{completion};
# my $extras = $args{extras} // {};
# my $bundling = $args{bundling} // 1;
# my %parsed_opts;
#
#
# my %opts;
# for my $ospec (keys %$gospec) {
# my $res = Getopt::Long::Util::parse_getopt_long_opt_spec($ospec)
# or die "Can't parse option spec '$ospec'";
# next if $res->{is_arg};
# $res->{min_vals} //= $res->{type} ? 1 : 0;
# $res->{max_vals} //= $res->{type} || $res->{opttype} ? 1:0;
# for my $o0 (@{ $res->{opts} }) {
# my @o = $res->{is_neg} && length($o0) > 1 ?
# ($o0, "no$o0", "no-$o0") : ($o0);
# for my $o (@o) {
# my $k = length($o)==1 ||
# (!$bundling && $res->{dash_prefix} eq '-') ?
# "-$o" : "--$o";
# $opts{$k} = {
# name => $k,
# ospec => $ospec,
# parsed => $res,
# };
# }
# }
# }
# my @optnames = sort keys %opts;
#
# my %seen_opts;
#
script/_genpw-base58 view on Meta::CPAN
# return;
# }
#
# my %keys;
# if ($cs->{keys}) {
# $keys{$_}++ for keys %{ $cs->{keys} };
# }
# if ($cs->{indices}) {
# $keys{$_}++ for keys %{ $cs->{indices} };
# }
# if ($cs->{req_keys}) {
# $keys{$_}++ for @{ $cs->{req_keys} };
# }
# if ($cs->{allowed_keys}) {
# $keys{$_}++ for @{ $cs->{allowed_keys} };
# }
#
# for (keys %{$args{args}{$arg} // {}}) {
# delete $keys{$_};
# }
#
# $fres = complete_hash_key(word => $word, hash => \%keys);
#
# };
# log_debug("[comp][periscomp] completion died: $@") if $@;
# unless ($fres) {
# log_trace("[comp][periscomp] no index completion from metadata possible, declining");
# goto RETURN_RES;
# }
#
# $fres = hashify_answer($fres);
# $fres->{static} //= $static && $word eq '' ? 1:0;
# RETURN_RES:
# log_trace("[comp][periscomp] leaving complete_arg_index, result=%s", $fres);
# $fres;
#}
#
#$SPEC{complete_cli_arg} = {
# v => 1.1,
# summary => 'Complete command-line argument using Rinci function metadata',
# description => <<'_',
#
#This routine uses <pm:Perinci::Sub::GetArgs::Argv> to generate <pm:Getopt::Long>
#specification from arguments list in Rinci function metadata and common options.
#Then, it will use <pm:Complete::Getopt::Long> to complete option names, option
#values, as well as arguments.
#
#_
# args => {
# meta => {
# summary => 'Rinci function metadata',
# schema => 'hash*',
# req => 1,
# },
# words => {
# summary => 'Command-line arguments',
# schema => ['array*' => {of=>'str*'}],
# req => 1,
# },
# cword => {
# summary => 'On which argument cursor is located (zero-based)',
# schema => 'int*',
# req => 1,
# },
# completion => {
# summary => 'Supply custom completion routine',
# description => <<'_',
#
#If supplied, instead of the default completion routine, this code will be called
#instead. Will receive all arguments that <pm:Complete::Getopt::Long> will pass,
#and additionally:
#
#* `arg` (str, the name of function argument)
#* `args` (hash, the function arguments formed so far)
#* `index` (int, if completing argument element value)
#
#_
# schema => 'code*',
# },
# per_arg_json => {
# summary => 'Will be passed to Perinci::Sub::GetArgs::Argv',
# schema => 'bool',
# },
# per_arg_yaml => {
# summary => 'Will be passed to Perinci::Sub::GetArgs::Argv',
# schema => 'bool',
# },
# common_opts => {
# summary => 'Common options',
# description => <<'_',
#
#A hash where the values are hashes containing these keys: `getopt` (Getopt::Long
#option specification), `handler` (Getopt::Long handler). Will be passed to
#`get_args_from_argv()`. Example:
#
# {
# help => {
# getopt => 'help|h|?',
# handler => sub { ... },
# summary => 'Display help and exit',
# },
# version => {
# getopt => 'version|v',
# handler => sub { ... },
# summary => 'Display version and exit',
# },
# }
#
#_
# schema => ['hash*'],
# },
# extras => {
# summary => 'Add extra arguments to completion routine',
# schema => 'hash',
# description => <<'_',
#
#The keys from this `extras` hash will be merged into the final `%args` passed to
#completion routines. Note that standard keys like `word`, `cword`, and so on as
#described in the function description will not be overwritten by this.
#
#_
( run in 1.798 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )