Skip to content

Commit

Permalink
Add support for command aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
mdom committed Dec 14, 2016
1 parent 048d03c commit 8746270
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
18 changes: 12 additions & 6 deletions bin/squaretag
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,14 @@ sub run {
minargs => 2,
opt_spec => \@rename_opts,
check => \&is_tag_file,
alias => ['rm'],
},
rename => {
cmd => sub { rename_files( shift, rename_tag(@_) ) },
minargs => 3,
opt_spec => \@rename_opts,
check => \&is_tag_file,
},
mv => {
cmd => sub { rename_files( shift, rename_tag(@_) ) },
minargs => 3,
opt_spec => \@rename_opts,
check => \&is_tag_file,
alias => ['mv'],
},
clear => {
cmd => sub { rename_files( shift, clear(@_) ) },
Expand All @@ -61,6 +57,16 @@ sub run {
},
);

for my $mode ( values %modes ) {
if ( my $aliases = $mode->{alias} ) {
for my $alias (@$aliases) {
if ( !exists $modes{$alias} ) {
$modes{$alias} = $mode;
}
}
}
}

if ( $mode && $modes{$mode} ) {
my $cmd = $modes{$mode}->{cmd};
my $minargs = $modes{$mode}->{minargs};
Expand Down
8 changes: 6 additions & 2 deletions t/08cli.t
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,12 @@ test_output ['remove','-v', 'foo', 'file[bar,foo].txt'], <<EOF;
file[bar,foo].txt -> file[bar].txt
EOF

test_output [qw(clear -v file[bar].txt)], <<EOF;
file[bar].txt -> file.txt
test_output [qw(mv -v bar foo file[bar].txt)], <<EOF;
file[bar].txt -> file[foo].txt
EOF

test_output [qw(clear -v file[foo].txt)], <<EOF;
file[foo].txt -> file.txt
EOF

done_testing;

0 comments on commit 8746270

Please sign in to comment.