Skip to content

Commit

Permalink
Revert "rename cmd to run, dwim more on multi"
Browse files Browse the repository at this point in the history
This reverts commit ad653ba.
  • Loading branch information
shadowcat-mst committed Nov 8, 2021
1 parent 27101ef commit d10b899
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 24 deletions.
35 changes: 16 additions & 19 deletions bin/plx
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ sub run_action_which {
say join(' ', 'plx', "--${action}", @call);
}

sub run_action_run {
sub run_action_cmd {
my ($self, @args) = @_;
my ($action, @call) = $self->_which(@args);
$self->${\"run_action_${action}"}(@call);
Expand Down Expand Up @@ -583,12 +583,11 @@ sub _parse_multi {
my ($self, @args) = @_;
my @multi;
MULTI: while (@args) {
barf "Expected multi arg {, got: $args[0]" unless $args[0] eq '{';
barf "Expected multi arg [, got: $args[0]" unless $args[0] eq '[';
shift @args;
my @action;
/^--/ or s/^/--/ for @args ? $args[0] : ();
while (my $el = shift @args) {
push @multi, \@action and next MULTI if $el eq '}';
push @multi, \@action and next MULTI if $el eq ']';
push @action, $el;
}
barf "Missing closing ] for multi";
Expand Down Expand Up @@ -621,7 +620,7 @@ sub run_action_showmulti {
sub run {
my ($self, $cmd, @args) = @_;
$cmd ||= '--help';
if ($cmd eq '{') {
if ($cmd eq '[') {
return $self->run_action_multi($cmd, @args);
}
if ($cmd =~ s/^--//) {
Expand All @@ -635,7 +634,7 @@ sub run {
$cmd = shift @args;
}
$self->ensure_layout_config_dir;
return $self->run_action_run($cmd, @args);
return $self->run_action_cmd($cmd, @args);
}

caller() ? 1 : __PACKAGE__->new->run(@ARGV);
Expand Down Expand Up @@ -821,7 +820,7 @@ a modified C<--cpanm> action that uses an inline C<App::cpanminus>.
plx --exec <cmd> <args> # exec()s with env vars set
plx --perl <args> # Run perl with args
plx --run <cmd> <args> # DWIM command:
plx --cmd <cmd> <args> # DWIM command:
cmd = perl -> --perl <args>
cmd = -<flag> -> --perl -<flag> <args>
Expand All @@ -833,15 +832,15 @@ a modified C<--cpanm> action that uses an inline C<App::cpanminus>.
exists bin/<name> -> --perl bin/<name> <args>
else -> --exec <name> <args>
plx --which <cmd> # Expands --run <cmd> without running
plx --which <cmd> # Expands --cmd <cmd> without running
plx <something> <args> # Shorthand for plx --run
plx <something> <args> # Shorthand for plx --cmd
plx --commands <filter>? # List available commands
plx --multi { <cmd1> <args1> } { ... } # Run multiple actions
plx --showmulti { ... } { ... } # Show multiple action running
plx { ... } { ... } # Shorthand for plx --multi
plx --multi [ <cmd1> <args1> ] [ ... ] # Run multiple actions
plx --showmulti [ ... ] [ ... ] # Show multiple action running
plx [ ... ] [ ... ] # Shorthand for plx --multi
plx --userinit <perl> # Init ~/.plx with ~/perl5 ll
plx --installself # Installs plx and cpanm into layout
Expand Down Expand Up @@ -952,9 +951,9 @@ Without arguments, sugar for C<--config perl>.
Otherwise, sets up the layout's environment variables and C<exec>s the
layout's perl with the given options and arguments.
=head2 --run
=head2 --cmd
plx --run <cmd> <args>
plx --cmd <cmd> <args>
cmd = perl -> --perl <args>
cmd = -<flag> -> --perl -<flag> <args>
Expand All @@ -980,7 +979,7 @@ anything with a non-perl shebang, one can add wrappers here ala:
plx --which <cmd>
Outputs the expanded form of a C<--run> invocation without running it.
Outputs the expanded form of a C<--cmd> invocation without running it.
=head2 --config
Expand Down Expand Up @@ -1063,15 +1062,13 @@ stripped and the filter is treated as a regexp.
=head2 --multi
plx --multi { --init } { --config perl set 5.28.0 }
plx --multi { init } { config perl set 5.28.0 }
plx --multi [ --init ] [ --config perl set 5.28.0 ]
Runs multiple plx commands from a single invocation delimited by C<[ ... ]>.
=head2 --showmulti
plx --showmulti { --init } { --config perl set 5.28.0 }
plx --showmulti { init } { config perl set 5.28.0 }
plx --showmulti [ --init ] [ --config perl set 5.28.0 ]
Outputs approximate plx invocations that would be run by C<--multi>.
Expand Down
10 changes: 5 additions & 5 deletions t/basic.t
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ subtest 'no .plx', sub {
reset_var_dir;
ok(do{ eval { plx "--$_" }; @$err }, "no init: --$_ failed") for qw(
base
run
cmd
commands
config
cpanm
Expand All @@ -60,12 +60,12 @@ plx_subtest 'plx --actions', sub {
like $err->[0], qr/No such action --actions/, 'not an action; see perldoc';
};

plx_subtest 'plx --run', sub {
plx qw(--run echo 'ehlo');
plx_subtest 'plx --cmd', sub {
plx qw(--cmd echo 'ehlo');
is_deeply $log, ['echo', "'ehlo'"];
plx qw(--run perl -MData::Dumper=Dumper -E 'Dumper(@ARGV)');
plx qw(--cmd perl -MData::Dumper=Dumper -E 'Dumper(@ARGV)');
is_deeply $log, [$path_perl, '-MData::Dumper=Dumper', '-E', "'Dumper(\@ARGV)'"];
# plx qw(--run /usr/local/bin/psql postgres);
# plx qw(--cmd /usr/local/bin/psql postgres);
# is_deeply $log, ['/usr/local/bin/psql', 'postgres'];
};

Expand Down

0 comments on commit d10b899

Please sign in to comment.