[Bps-public-commit] Prophet branch, master, updated. e6e6e410d076acf6481aea9b0601241c3a831080

sunnavy at bestpractical.com sunnavy at bestpractical.com
Tue Jun 16 09:36:12 EDT 2009


The branch, master has been updated
       via  e6e6e410d076acf6481aea9b0601241c3a831080 (commit)
       via  48823130bcd51d46a71bc57440c85b458d832d45 (commit)
      from  80b9f5037a47b27a70305e7a44197ad4ec3b280b (commit)

Summary of changes:
 lib/Prophet/CLI/Command/Aliases.pm |    4 +--
 lib/Prophet/CLI/Dispatcher.pm      |   27 ++++++++++++++++--
 t/aliases.t                        |   54 ++++++++++++++++++++++++++++++-----
 3 files changed, 71 insertions(+), 14 deletions(-)

- Log -----------------------------------------------------------------
commit 48823130bcd51d46a71bc57440c85b458d832d45
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Tue Jun 16 21:28:14 2009 +0800

    update tests for aliases: remove dashes, also add new tests for it too

diff --git a/t/aliases.t b/t/aliases.t
index ae007e2..44493b9 100644
--- a/t/aliases.t
+++ b/t/aliases.t
@@ -2,7 +2,7 @@
 #
 use warnings;
 use strict;
-use Prophet::Test 'no_plan';
+use Prophet::Test tests => 19;
 use File::Temp qw/tempfile/;
 
 $ENV{'PROPHET_APP_CONFIG'} = (tempfile(UNLINK => 1))[1];
@@ -16,44 +16,80 @@ is_deeply( $aliases, {}, 'initial alias is empty' );
 
 my @cmds = (
     {
-        cmd => [ '--add', 'pull -a=pull --all' ],
+        cmd => [ 'show' ],
+        output  => qr/^\s*$/,
+        comment => 'show empty aliases',
+    },
+
+    {
+        cmd => [ 'add', 'pull -a=pull --all' ],
         output  => qr/added alias 'pull -a = pull --all/,
         comment => 'add a new alias',
     },
     {
-        cmd => [ '--add', 'pull -a=pull --all' ],
+        cmd => [ 'add', 'pull -a=pull --all' ],
         output  => qr/alias 'pull -a = pull --all' isn't changed, won't update/,
         comment => 'add the same alias will not change anything',
     },
     {
 
         # this alias is bad, please don't use it in real life
-        cmd => [ '--set', 'pull -a=pull --local' ],
+        cmd => [ 'set', 'pull -a=pull --local' ],
         output =>
           qr/changed alias 'pull -a' from 'pull --all' to 'pull --local'/,
         comment =>
           q{changed alias 'pull -a' from 'pull --all' to 'pull --local'},
     },
     {
-        cmd     => [ '--delete', 'pull -a' ],
+        cmd     => [ 'delete', 'pull -a' ],
         output  => qr/deleted alias 'pull -a = pull --local'/,
         comment => q{deleted alias 'pull -a = pull --local'},
     },
     {
-        cmd     => [ '--delete', 'pull -a' ],
+        cmd     => [ 'delete', 'pull -a' ],
         output  => qr/didn't find alias 'pull -a'/,
         comment => q{delete an alias that doesn't exist any more},
     },
     {
-        cmd => [ '--add', 'pull -a=pull --all' ],
+        cmd => [ 'add', 'pull -a=pull --all' ],
         output  => qr/added alias 'pull -a = pull --all/,
         comment => 'readd a new alias',
     },
     {
-        cmd => [ '--add', 'pull -l=pull --local' ],
+        cmd => [ 'add', 'pull -l=pull --local' ],
         output  => qr/added alias 'pull -l = pull --local/,
         comment => 'add a new alias',
     },
+    {
+        cmd => [ 'show' ],
+        output  => qr/alias pull -a = pull --all/s,
+        comment => 'show',
+    },
+    {
+        cmd => [ 'show' ],
+        output  => qr/alias pull -l = pull --local/s,
+        comment => 'show',
+    },
+    {
+        cmd => [ 'add', 'foo', 'bar', '=', 'bar',  'baz' ],
+        output  => qr/added alias 'foo bar = bar baz'/,
+        comment => 'added alias foo bar',
+    },
+    {
+        cmd => [ 'foo', 'bar', '=', 'bar',  'baz' ],
+        output  => qr/alias 'foo bar = bar baz' isn't changed, won't update/,
+        comment => 'readd alias foo bar',
+    },
+    {
+        cmd => [ 'delete', 'foo', 'bar' ],
+        output  => qr/deleted alias 'foo bar = bar baz'/,
+        comment => 'deleted alias foo bar',
+    },
+    {
+        cmd => [ 'set', 'foo', 'bar', '=bar baz'],
+        output => qr/added alias 'foo bar = bar baz'/,
+        comment => 'readd alias foo bar = bar baz',
+    },
 );
 
 for my $item ( @cmds ) {
@@ -70,6 +106,7 @@ is_deeply(
     {
         'pull -l' => 'pull --local',
         'pull -a' => 'pull --all',
+        'foo bar' => 'bar baz',
     },
     'non empty aliases',
 );
@@ -81,6 +118,7 @@ open my $fh, '<', $ENV{'PROPHET_APP_CONFIG'}
 { local $/; $content = <$fh>; }
 is( $content, <<EOF, 'content in config' );
 alias pull -l = pull --local
+alias foo bar = bar baz
 alias pull -a = pull --all
 EOF
 

commit e6e6e410d076acf6481aea9b0601241c3a831080
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Tue Jun 16 21:28:54 2009 +0800

    update aliases cmd

diff --git a/lib/Prophet/CLI/Command/Aliases.pm b/lib/Prophet/CLI/Command/Aliases.pm
index 0875bbb..b5f3330 100644
--- a/lib/Prophet/CLI/Command/Aliases.pm
+++ b/lib/Prophet/CLI/Command/Aliases.pm
@@ -5,8 +5,6 @@ use Params::Validate qw/validate/;
 extends 'Prophet::CLI::Command';
 with 'Prophet::CLI::TextEditorCommand';
 
-sub ARG_TRANSLATIONS { shift->SUPER::ARG_TRANSLATIONS(),  a => 'add', d => 'delete', s => 'show' };
-
 sub run {
     my $self     = shift;
     my $template = $self->make_template;
@@ -16,7 +14,7 @@ sub run {
         return;
     }
 
-    # --add is the same as --set
+    # add is the same as set
     if ( $self->context->has_arg('add') ) {
         $self->context->set_arg('set', $self->arg('add') )
     }
diff --git a/lib/Prophet/CLI/Dispatcher.pm b/lib/Prophet/CLI/Dispatcher.pm
index 8c81586..9332d56 100644
--- a/lib/Prophet/CLI/Dispatcher.pm
+++ b/lib/Prophet/CLI/Dispatcher.pm
@@ -60,9 +60,9 @@ on config   => run_command("Config");
 on settings => run_command("Settings");
 on log      => run_command("Log");
 on shell    => run_command("Shell");
-on aliases  => run_command("Aliases");
-on export => run_command('Export');
-on info   => run_command('Info');
+on export   => run_command('Export');
+on info     => run_command('Info');
+on aliases     => run_command('Aliases');
 
 on push => sub {
     my $self = shift;
@@ -74,6 +74,27 @@ on push => sub {
     run('merge', $self, @_);
 };
 
+on qr/^alias(?:es)?\s*(.*)/ => sub {
+    my ( $self ) = @_;
+    my $arg = $1;
+    if ( $arg =~ /^show\b/ ) {
+        $self->context->set_arg(show => 1);
+    }
+    elsif ( $arg =~ /^delete\s+(.*)/ ) {
+        $self->context->set_arg(delete => $1);
+    }
+    elsif ( $arg =~ /^(?:add|set)?\s+(.*)/ ) {
+        $self->context->set_arg(set => $1);
+    }
+    elsif ( $arg =~ /=/ ) {
+        $self->context->set_arg(set => $arg);
+    }
+    else {
+        die 'no idea what you mean, sorry';
+    }
+    run( 'aliases', $self, @_ );
+};
+
 on history => run_command('History');
 
 sub run_command {

-----------------------------------------------------------------------



More information about the Bps-public-commit mailing list