Skip to content

Instantly share code, notes, and snippets.

@ingydotnet
Created February 12, 2016 22:10
Show Gist options
  • Save ingydotnet/3917d5567b92269d9740 to your computer and use it in GitHub Desktop.
Save ingydotnet/3917d5567b92269d9740 to your computer and use it in GitHub Desktop.
appspec command_string
diff --git a/ext/App-Spec-p5/lib/App/Spec/Completion/Bash.pm b/ext/App-Spec-p5/lib/App/Spec/Completion/Bash.pm
index 56ca853..a1f4246 100644
--- a/ext/App-Spec-p5/lib/App/Spec/Completion/Bash.pm
+++ b/ext/App-Spec-p5/lib/App/Spec/Completion/Bash.pm
@@ -261,6 +261,7 @@ sub dynamic_completion {
my $name = $p->name;
my $def = $p->completion;
my $command = $def->{command};
+ my $command_string = $def->{command_string};
my $op = $def->{op};
my @args;
my $appname = $self->spec->name;
@@ -279,42 +280,51 @@ $function_name() \{
\}
EOM
}
- elsif ($command) {
- for my $arg (@$command) {
- unless (ref $arg) {
- push @args, "'$arg'";
- next;
- }
- if (my $replace = $arg->{replace}) {
- if (ref $replace eq 'ARRAY') {
- my @repl = @$replace;
- if ($replace->[0] eq 'SHELL_WORDS') {
- my $num = $replace->[1];
- my $index = "\$COMP_CWORD";
- if ($num ne 'CURRENT') {
- if ($num =~ m/^-/) {
- $index .= $num;
- }
- else {
- $index = $num - 1;
+ elsif ($command or $command_string) {
+
+ my $string = '';
+ if ($command) {
+
+ for my $arg (@$command) {
+ unless (ref $arg) {
+ push @args, "'$arg'";
+ next;
+ }
+ if (my $replace = $arg->{replace}) {
+ if (ref $replace eq 'ARRAY') {
+ my @repl = @$replace;
+ if ($replace->[0] eq 'SHELL_WORDS') {
+ my $num = $replace->[1];
+ my $index = "\$COMP_CWORD";
+ if ($num ne 'CURRENT') {
+ if ($num =~ m/^-/) {
+ $index .= $num;
+ }
+ else {
+ $index = $num - 1;
+ }
}
+ my $string = qq{"\$\{COMP_WORDS\[$index\]\}"};
+ push @args, $string;
}
- my $string = qq{"\$\{COMP_WORDS\[$index\]\}"};
- push @args, $string;
}
- }
- else {
- if ($replace eq "SELF") {
- push @args, "\$program";
+ else {
+ if ($replace eq "SELF") {
+ push @args, "\$program";
+ }
}
}
}
+ $string = "@args";
+ }
+ elsif (defined $command_string) {
+ $string = $command_string;
}
my $varname = "__${name}_completion";
$function = <<"EOM";
$function_name() \{
- local param_$name=`@args`
+ local param_$name=`$string`
_${appname}_compreply "\$param_$name"
\}
EOM
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment