App-orgadb
view release on metacpan or search on metacpan
lib/App/orgadb/Select/Shell.pm view on Meta::CPAN
join(', ', @{ $res->[3]{'func.missing_args'} })];
last;
}
# validate using schemas in Rinci metadata
my $args = $res->[2];
$res = Perinci::Sub::ValidateArgs::validate_args_using_meta(
args => $args,
meta => $args{meta},
);
unless ($res->[0] == 200) {
last;
}
$res = $args{code}->(%$args, -shell => $self);
}
my $fmt = $opts->{fmt} //
$res->[3]{"x.app.orgadb_sel.default_format"} //
'text';
print Perinci::Result::Format::Lite::format($res, $fmt);
}
sub comp_ {
require Complete::Bash;
require Complete::Util;
my $self = shift;
my ($cmd, $word0, $line, $start) = @_;
local $self->{_in_completion} = 1;
# add commands
my @res = ("help", "exit");
push @res, grep {/\A\w+\z/} keys %App::orgadb::Select::Shell::Commands::SPEC;
my $comp = Complete::Bash::format_completion({
path_sep => '/',
words => Complete::Util::complete_array_elem(
array=>\@res, word=>$word0),
}, {as => 'array'});
if ($self->setting("debug_completion")) {
say "DEBUG: Completion (1): ".join(", ", @$comp);
}
@$comp;
}
sub _err {
require Perinci::Result::Format::Lite;
my $self = shift;
print Perinci::Result::Format::Lite::format($_[0], "text");
}
sub catch_run {
my $self = shift;
my ($cmd, @argv) = @_;
$self->_err([404, "No such command"]);
return;
}
sub catch_comp {
require Perinci::Sub::Complete;
require Complete::Bash;
require Complete::Util;
my $self = shift;
my ($cmd, $word, $line, $start) = @_;
local $self->{_in_completion} = 1;
my $meta = $App::orgadb::Selec::Shell::Commands::SPEC{$cmd};
return () unless $meta;
my ($words, $cword) = @{ Complete::Bash::parse_cmdline(
$line, $start+length($word), {truncate_current_word=>1}) };
($words, $cword) = @{ Complete::Bash::join_wordbreak_words(
$words, $cword) };
shift @$words; $cword--; # strip program name
$opts = {};
my $res = Perinci::Sub::Complete::complete_cli_arg(
words => $words, cword => $cword,
meta => $meta, common_opts => $common_opts,
extras => {-shell => $self},
);
$res = _hashify_compres($res);
@{ Complete::Bash::format_completion({
path_sep => '/',
esc_mode => 'default',
words => Complete::Util::complete_array_elem(
array=>$res->{words}, word=>$word),
}, {as=>'array'})};
}
sub _hashify_compres {
ref($_[0]) eq 'HASH' ? $_[0] : {words=>$_[0]};
}
my $installed = 0;
sub _install_cmds {
my $class = shift;
return if $installed;
require App::orgadb::Select::Shell::Commands;
require Complete::Util;
for my $cmd (sort keys %App::orgadb::Select::Shell::Commands::SPEC) {
next unless $cmd =~ /\A\w+\z/; # only functions
log_trace("Installing command $cmd ...");
my $meta = $App::orgadb::Select::Shell::Commands::SPEC{$cmd};
my $code = \&{"App::orgadb::Select::Shell::Commands::$cmd"};
*{"smry_$cmd"} = sub { $meta->{summary} };
*{"run_$cmd"} = sub {
my $self = shift;
$self->_run_cmd(name=>$cmd, meta=>$meta, argv=>\@_, code=>$code);
};
*{"comp_$cmd"} = sub {
require Complete::Bash;
( run in 0.772 second using v1.01-cache-2.11-cpan-39bf76dae61 )