[Bps-public-commit] Prophet branch, master, updated. 0.72-3-gc1b563b

Nelson Elhage nelhage at bestpractical.com
Wed Sep 9 23:02:02 EDT 2009


The branch, master has been updated
       via  c1b563b7cf7e19a911cbdd598a15a70c4238ac48 (commit)
       via  f0c4a21c8c4535c8d97869d5f23eb1de7f16149b (commit)
       via  5e561963f8e4a830635017820495195baddc9cb7 (commit)
      from  0fa85151d45194bad2fde171ba976352349d9a06 (commit)

Summary of changes:
 lib/Prophet/CLI.pm      |   53 ++++++++++++++++++++++++----------------------
 t/aliases_with_quotes.t |   12 ++++++++-
 2 files changed, 38 insertions(+), 27 deletions(-)

- Log -----------------------------------------------------------------
commit 5e561963f8e4a830635017820495195baddc9cb7
Author: Nelson Elhage <nelhage at mit.edu>
Date:   Wed Sep 9 18:12:50 2009 -0400

    aliases_with_quotes.t: Actually capture $bug_id.
    
    (?{...}) has ... strange ... scoping semantics. The old code was
    resulting in $bug_id getting assigned undef, which caused the later
    tests to always pass.
    
    Signed-off-by: Nelson Elhage <nelhage at mit.edu>

diff --git a/t/aliases_with_quotes.t b/t/aliases_with_quotes.t
index 3dd2e25..ae2ac17 100644
--- a/t/aliases_with_quotes.t
+++ b/t/aliases_with_quotes.t
@@ -2,13 +2,13 @@
 #
 use warnings;
 use strict;
-use Prophet::Test tests => 13;
+use Prophet::Test tests => 15;
 
 as_alice {
     run_command('init');
     my ( $output, $error ) =
       run_command( qw/create --type Bug --/, 'summary=foo bar' );
-    my $bug_id;
+    our $bug_id;
     like(
         $output,
         qr/Created Bug \d+ \((\S+)\)(?{ $bug_id = $1 })/,

commit f0c4a21c8c4535c8d97869d5f23eb1de7f16149b
Author: Nelson Elhage <nelhage at mit.edu>
Date:   Wed Sep 9 18:15:23 2009 -0400

    Add a failing test showing another quoting problem with aliases.
    
    Signed-off-by: Nelson Elhage <nelhage at mit.edu>

diff --git a/t/aliases_with_quotes.t b/t/aliases_with_quotes.t
index ae2ac17..951f161 100644
--- a/t/aliases_with_quotes.t
+++ b/t/aliases_with_quotes.t
@@ -2,7 +2,7 @@
 #
 use warnings;
 use strict;
-use Prophet::Test tests => 15;
+use Prophet::Test tests => 16;
 
 as_alice {
     run_command('init');
@@ -42,6 +42,10 @@ as_alice {
             cmd => [ 'add', 'balanced_2=search --type Bug -- summary "foo bar"' ],
             comment => 'add a new alias',
         },
+        {
+            cmd => [ 'add', 's=search' ],
+            comment => 'add a new alias',
+        }
     );
 
     for my $item (@cmds) {
@@ -60,4 +64,8 @@ as_alice {
     like( $output, qr/$bug_id/, 'quote in aliase like --summary="foo bar"' );
     ($output) = run_command('balanced_2');
     like( $output, qr/$bug_id/, 'quote in aliase like --summary "foo bar"' );
+
+    ($output, $error) = run_command(qw(s --type Bug), "--summary=foo bar");
+    like( $output, qr/$bug_id/, 'Arguments to aliases with spaces are preserved' );
+    diag($error) if $error;
 };

commit c1b563b7cf7e19a911cbdd598a15a70c4238ac48
Author: Nelson Elhage <nelhage at mit.edu>
Date:   Wed Sep 9 19:06:43 2009 -0400

    Reimplement alias expansion in terms of lists of argument words.
    
    By never re-concatenating words, and only tokenizing at the very
    beginning, we fix some bugs with handling quoted words.

diff --git a/lib/Prophet/CLI.pm b/lib/Prophet/CLI.pm
index a45a678..412153c 100644
--- a/lib/Prophet/CLI.pm
+++ b/lib/Prophet/CLI.pm
@@ -8,6 +8,7 @@ use Prophet::CLI::Dispatcher;
 use Prophet::CLIContext;
 
 use List::Util 'first';
+use Text::ParseWords qw(shellwords);
 
 has app_class => (
     is      => 'rw',
@@ -92,17 +93,15 @@ sub run_one_command {
 
     if ($self->app_handle->local_replica_url) {
         my $aliases = $self->app_handle->config->aliases;
-        for my $alias ( keys %$aliases ) {
+        while (my ($alias, $replacement) = each %$aliases ) {
             my $command = $self->_command_matches_alias(
-                $ori_cmd, $alias, $aliases->{$alias},
-            ) || next;
+                \@args, $alias, $replacement,
+               ) || next;
 
             # we don't want to recursively call if people stupidly write
             # alias pull --local = pull --local
-            next if ( $command eq $ori_cmd );
-            require Text::ParseWords;
-            return $self->run_one_command(
-                Text::ParseWords::shellwords($command) );
+            next if ( join(' ', @$command) eq $ori_cmd );
+            return $self->run_one_command(@$command);
         }
     }
     #  really, we shouldn't be doing this stuff from the command dispatcher
@@ -125,28 +124,32 @@ sub run_one_command {
 
 sub _command_matches_alias {
     my $self  = shift;
-    my $cmd   = shift;
-    my $alias = shift;
-    my $dispatch_to = shift;;
-    if ( $cmd =~ /^\Q$alias\E\b\s*(.*)$/ ) {
-        my $rest = $1;
-        if ($dispatch_to =~ m{\$\d+\b}) {
-            my @captures = $self->tokenize($rest);
-            $dispatch_to =~ s/\$(\d+)\b/$captures[$1 - 1]||""/ge;
-        } else {
-            $dispatch_to .= " " . $rest;
+    my @words = @{+shift};
+    my @alias = shellwords(shift);
+    my @expansion = shellwords(shift);
+
+    # Compare @words against @alias
+    return if(scalar(@words) < scalar(@alias));
+
+    while(@alias) {
+        if(shift @words ne shift @alias) {
+            return;
         }
-        return $dispatch_to;
     }
-    return undef;
-}
 
+    # @words now contains the remaining words given on the
+    # command-line, and @expansion contains the words in the
+    # expansion.
 
-sub tokenize {
-    my $self = shift;
-    my $string = shift;
-    my @tokens = split(/\s+/,$string); # XXX TODO deal with quoted tokens
-    return @tokens;
+    if (first sub {m{\$\d+\b}}, @expansion) {
+        # Expand $n placeholders
+        for (@expansion) {
+            s/\$(\d+)\b/$words[$1 - 1]||""/ge;
+        }
+        return [@expansion];
+    } else {
+        return [@expansion, @words];
+    }
 }
 
 sub is_interactive {

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



More information about the Bps-public-commit mailing list