[Bps-public-commit] Prophet branch, config-gitlike, updated. 7fde2443ca389c60ab8cb294854df61efd90e175

spang at bestpractical.com spang at bestpractical.com
Mon Jun 22 16:20:15 EDT 2009


The branch, config-gitlike has been updated
       via  7fde2443ca389c60ab8cb294854df61efd90e175 (commit)
       via  fd24abf70b083688a5f0349826541a8b80503c8a (commit)
       via  849abbb6f4826e24e2157ac0b5d62a2a17eacd7b (commit)
       via  032770b54b43a734cf4991d3663a642a383ed909 (commit)
       via  723b5f782014599fa53fdbc35f724b79161a3cd5 (commit)
       via  76646e0721480fdbb821b42c2805ca2e7a0c9e8d (commit)
       via  d5faf258c2229b64b731f983c6723d1247645c25 (commit)
       via  3d578d36f53fa5bd4ed96cff62d91781518e2422 (commit)
       via  19ee6b82d3a7a62ac08e937273987d2f3a790d9d (commit)
       via  ee0c8885e38cf9ee42f8f3ee85329e80d8dc14ff (commit)
       via  e7b9d4e9e7f47f7f49ebc24fff35e30c01fa811e (commit)
       via  90871e7db8f4ad847deee8e03d58d1edd96111b9 (commit)
       via  abf81e332359be77e432ec451fb3a8d4504138e5 (commit)
       via  05d94608c78d5b51001537bc37c6753e1deeed19 (commit)
       via  009ad5b5dcc9e89894fa47d064435eb46b39e0c4 (commit)
       via  36397111f49b83c95351aab41c373e66c443b2ab (commit)
       via  e6e6e410d076acf6481aea9b0601241c3a831080 (commit)
       via  48823130bcd51d46a71bc57440c85b458d832d45 (commit)
      from  b50d1d02112e12cf0b1c4881b6c1fba4ded1b7e7 (commit)

Summary of changes:
 lib/Prophet/CLI.pm                   |    2 +-
 lib/Prophet/CLI/Command.pm           |    1 +
 lib/Prophet/CLI/Command/Aliases.pm   |  137 +++++++++++++++++++++++-----------
 lib/Prophet/CLI/Command/Merge.pm     |    2 +-
 lib/Prophet/CLI/Command/Publish.pm   |    4 +-
 lib/Prophet/CLI/Dispatcher.pm        |   31 +++++++-
 lib/Prophet/CLI/PublishCommand.pm    |    4 +
 lib/Prophet/CLI/TextEditorCommand.pm |   33 ++++++--
 lib/Prophet/Config.pm                |  122 +++++++++++++++++++++---------
 lib/Prophet/Record.pm                |    8 ++-
 lib/Prophet/Replica/prophet.pm       |    7 +-
 lib/Prophet/Replica/sqlite.pm        |   18 +++-
 t/aliases.t                          |   51 ++++++++++--
 t/log.t                              |    3 +-
 14 files changed, 309 insertions(+), 114 deletions(-)

- Log -----------------------------------------------------------------
commit 36397111f49b83c95351aab41c373e66c443b2ab
Author: Christine Spang <spang at mit.edu>
Date:   Thu Jun 18 15:23:31 2009 +0300

    Update aliases command to use group_set.

diff --git a/lib/Prophet/CLI/Command/Aliases.pm b/lib/Prophet/CLI/Command/Aliases.pm
index 36f6cf1..b9b7230 100644
--- a/lib/Prophet/CLI/Command/Aliases.pm
+++ b/lib/Prophet/CLI/Command/Aliases.pm
@@ -72,7 +72,6 @@ sub run {
 
     }
     else {
-
         my $done = 0;
 
         while ( !$done ) {
@@ -86,7 +85,7 @@ sub make_template {
 
     my $content = '';
    
-    $content .= "# Format: alias new_cmd = cmd\n"
+    $content .= "# Format: new_cmd = cmd\n"
       unless $self->context->has_arg('show');
 
     # get all settings records
@@ -94,7 +93,7 @@ sub make_template {
 
     if ( $aliases ) {
         for my $key ( keys %$aliases ) {
-            $content .= "alias $key = $aliases->{$key}\n";
+            $content .= "$key = $aliases->{$key}\n";
         }
     }
 
@@ -107,7 +106,7 @@ sub parse_template {
 
     my %parsed;
     for my $line ( split( /\n/, $template ) ) {
-        if ( $line =~ /^\s*alias\s+(.+?)\s*=\s*(.+?)\s*$/ ) {
+        if ( $line =~ /^\s*([^#].*?)\s*=\s*(.+?)\s*$/ ) {
             $parsed{$1} = $2;
         }
     }
@@ -133,34 +132,48 @@ sub process_template {
 
     my @deleted = grep { !$config->{$_} } sort keys %$aliases;
 
-    # TODO: 'set' all at once after implementing hash sets
-    for my $add ( @added ) {
-        print 'Added alias ' . "'$add' = '$config->{$add}'\n";
-        $c->set(
-            key => "alias.$add",
-            value => $config->{$add},
-            filename => $c->replica_config_file,
+    # attempt to set all added/changed/deleted aliases at once
+    my @to_set = (
+        (map { { key => "alias.'$_'", value => $config->{$_} } }
+            (@added, @changed)),
+        (map { { key => "alias.'$_'" } } @deleted),
+    );
+
+    eval {
+        $c->group_set(
+            $c->replica_config_file,
+            \@to_set,
         );
-    }
-
-    for my $change (@changed) {
-        print 'Changed alias ' . "'$change' from '$aliases->{$change}' to '$config->{$change}'\n";
-        $c->set(
-            key => "alias.$change",
-            value => $config->{$change},
-            filename => $c->replica_config_file,
+    };
+    # if we fail, prompt the user to re-edit
+    # TODO: this doesn't really work correctly.
+    # Also, handle_template_errors gives messages that are very
+    # much tailored towards SD's ticket editing facility.
+    # Should genericise that.
+    if ($@) {
+        warn $@;
+        return $self->handle_template_errors(
+            rtype => 'aliases',
+            template_ref => $args{template},
+            bad_template => $args{edited},
+            error => "$@",
         );
     }
+    # otherwise, print out what changed and return happily
+    else {
+        for my $add ( @added ) {
+            print 'Added alias ' . "'$add' = '$config->{$add}'\n";
+        }
+        for my $change (@changed) {
+            print "Changed alias '$change' from '$aliases->{$change}'"
+                  ."to '$config->{$change}'\n";
+        }
+        for my $delete ( @deleted ) {
+            print "Deleted alias '$delete'\n";
+        }
 
-    for my $delete ( @deleted ) {
-        print "Deleted alias '$delete'\n";
-        $c->set(
-            key => "alias.$delete",
-            filename => $c->replica_config_file,
-        );
+        return 1;
     }
-
-    return 1;
 }
 
 __PACKAGE__->meta->make_immutable;

commit ee0c8885e38cf9ee42f8f3ee85329e80d8dc14ff
Author: Christine Spang <spang at mit.edu>
Date:   Mon Jun 22 10:22:32 2009 +0300

    Initial --user/--global flags for editing aliases

diff --git a/lib/Prophet/CLI/Command/Aliases.pm b/lib/Prophet/CLI/Command/Aliases.pm
index b9b7230..416e430 100644
--- a/lib/Prophet/CLI/Command/Aliases.pm
+++ b/lib/Prophet/CLI/Command/Aliases.pm
@@ -5,6 +5,15 @@ use Params::Validate qw/validate/;
 extends 'Prophet::CLI::Command';
 with 'Prophet::CLI::TextEditorCommand';
 
+has config_filename => (
+    is => 'rw',
+    isa => 'Str',
+    lazy => 1,
+    default => sub {
+        $_[0]->app_handle->config->replica_config_file;
+    },
+);
+
 sub ARG_TRANSLATIONS { shift->SUPER::ARG_TRANSLATIONS(),  a => 'add', d => 'delete', s => 'show' };
 
 sub run {
@@ -18,6 +27,13 @@ sub run {
         return;
     }
 
+    if ($self->has_arg('global')) {
+        $self->config_filename($config->global_file);
+    }
+    elsif ($self->has_arg('user')) {
+        $self->config_filename($config->user_file);
+    }
+
     # --add is the same as --set
     if ( $self->context->has_arg('add') ) {
         $self->context->set_arg('set', $self->arg('add') )
@@ -34,7 +50,7 @@ sub run {
                         $config->set(
                             key => "alias.$1",
                             value => $2,
-                            filename => $config->replica_config_file,
+                            filename => $self->config_filename,
                         );
                         print
                           "changed alias '$1' from '$old' to '$2'\n";
@@ -47,7 +63,7 @@ sub run {
                     $config->set(
                         key => "alias.$1",
                         value => $2,
-                        filename => $config->replica_config_file,
+                        filename => $self->config_filename,
                     );
                     print "added alias '$1 = $2'\n";
                 }
@@ -62,7 +78,7 @@ sub run {
 
                 $config->set(
                     key => "alias.$key",
-                    filename => $config->replica_config_file,
+                    filename => $self->config_filename,
                 );
             }
             else {
@@ -141,7 +157,7 @@ sub process_template {
 
     eval {
         $c->group_set(
-            $c->replica_config_file,
+            $self->config_filename,
             \@to_set,
         );
     };

commit 19ee6b82d3a7a62ac08e937273987d2f3a790d9d
Author: Christine Spang <spang at mit.edu>
Date:   Mon Jun 22 10:23:39 2009 +0300

    Update Prophet::Config pod a bit

diff --git a/lib/Prophet/Config.pm b/lib/Prophet/Config.pm
index ba4040e..a15d409 100644
--- a/lib/Prophet/Config.pm
+++ b/lib/Prophet/Config.pm
@@ -8,7 +8,7 @@ has app_handle => (
     is => 'ro',
     weak_ref => 1,
     isa => 'Prophet::App',
-    required => 0
+    required => 1
 );
 
 # reload config after setting values
@@ -105,54 +105,74 @@ Prophet::Config
 
 =head1 SYNOPSIS
 
-    In the Prophet config file (see L</app_config_file>):
+From, for example, a class that inherits from Prophet::App:
+
+    has config => (
+        is      => 'rw',
+        isa     => 'Prophet::Config',
+        default => sub {
+            my $self = shift;
+            return Prophet::Config->new(
+                app_handle => $self,
+                confname => 'prophetrc',
+            );
+        },
+    );
 
-      prefer_luids: 1
-      summary_format_ticket = %4s },$luid | %-11.11s,status | %-70.70s,summary
 
 =head1 DESCRIPTION
 
 This class represents the configuration of Prophet and the application built on
-top of it.
+top of it. It's just an instance of L<Config::GitLike|Config::GitLike> with
+a few small customizations and additions.
 
 =head1 METHODS
 
-=head2 new
-
-Takes no arguments. Automatically loads the config for you.
+=head2 new( confname => 'prophetrc', app_handle => $instance_of_prophet_app )
 
-=cut
+Initialize the configuration. Does NOT load the config for you! You need to
+call L<load|Config::GitLike/"load"> for that. The configuration will also
+load automatically the first time your prophet application tries to
+L<get|Config::GitLike/"get"> a config variable.
 
-=head2 app_config_file
+Both constructor arguments are required.
 
-The file which controls configuration for this application
-(the $PROPHET_APP_CONFIG environmental variable, C<$PROPHET_REPO/config>,
-or C<$HOME/.prophetrc>, in that order).
+=head2 replica_config_file
 
-=head2 load_from_files [files]
+The replica-specific configuration file, or the configuration file given
+by C<PROPHET_APP_CONFIG> if that environmental variable is set.
 
-Loads the given config files. If no files are passed in, it will use the
-default of L</app_config_file>.
+=head2 aliases
 
-=head2 load_from_file file
+A convenience method that gets you a hash (or a hashref, depending on context)
+of all currently defined aliases. (Basically, every entry in the 'alias'
+section of the config file.)
 
-Loads the given config file.
+=head2 sources
 
-=head2 get
+A convenience method that gets you a hash (or a hashref, depending on context)
+of all currently defined source replicas, in the format { 'name' =>
+{ url => 'URL', uuid => 'UUID } }. (Basically, every entry in the 'replica'
+section of the config file.)
 
-Gets a specific config setting.
-
-=head2 set
+=head2 display_name_for_uuid UUID
 
-Sets a specific config setting.
+Returns a "friendly" id for the given uuid.
 
-=head2 list
+TODO: regexp search for 'replica.(.*).UUID' and extract the section
 
-Lists all configuration options.
+=head1 CONFIG VARIABLES
 
-=head2 display_name_for_uuid UUID
+The following config variables are currently used in various places in
+Prophet:
 
-Returns a "friendly" id for the given uuid.
+<record-type>.summary-format
+record.summary-format
+user.email-address
+alias.<alias>
 
-=cut
+=head1 SEE ALSO
 
+Most of the useful methods for getting and setting configuration variables
+actually come from L<Config::GitLike|Config::GitLike>. See that module's
+documentation for details.

commit 3d578d36f53fa5bd4ed96cff62d91781518e2422
Merge: 19ee6b8... e7b9d4e...
Author: Christine Spang <spang at mit.edu>
Date:   Mon Jun 22 10:31:10 2009 +0300

    Merge back master since sunnavy did some work on aliases and I want to make sure I'm not creating crazy conflicts

diff --cc lib/Prophet/CLI/Command/Aliases.pm
index 416e430,b5f3330..27d7b3d
--- a/lib/Prophet/CLI/Command/Aliases.pm
+++ b/lib/Prophet/CLI/Command/Aliases.pm
@@@ -27,14 -14,7 +27,14 @@@ sub run 
          return;
      }
  
 +    if ($self->has_arg('global')) {
 +        $self->config_filename($config->global_file);
 +    }
 +    elsif ($self->has_arg('user')) {
 +        $self->config_filename($config->user_file);
 +    }
 +
-     # --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 --cc t/aliases.t
index a7ac708,44493b9..9aa3223
--- a/t/aliases.t
+++ b/t/aliases.t
@@@ -2,15 -2,10 +2,15 @@@
  #
  use warnings;
  use strict;
- use Prophet::Test 'no_plan';
- use File::Temp qw/tempdir tempfile/;
+ use Prophet::Test tests => 19;
+ use File::Temp qw/tempfile/;
  
 -$ENV{'PROPHET_APP_CONFIG'} = (tempfile(UNLINK => 1))[1];
 +$ENV{'PROPHET_REPO'} = $Prophet::Test::REPO_BASE . '/repo-' . $$;
 +$ENV{'PROPHET_APP_CONFIG'} = (tempfile(UNLINK => !$ENV{PROPHET_DEBUG}))[1];
 +diag("Using config file $ENV{PROPHET_APP_CONFIG}");
 +
 +# since we don't initialize the db for these tests, make the repo dir
 +mkdir $ENV{PROPHET_REPO};
  
  use_ok('Prophet::CLI');
  use_ok('Prophet::Config');
@@@ -51,12 -51,12 +57,12 @@@ my @cmds = 
          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',
 +        comment => 'read 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',
      },
@@@ -89,10 -117,8 +126,16 @@@ open my $fh, '<', $ENV{'PROPHET_APP_CON
    or die "failed to open $ENV{'PROPHET_APP_CONFIG'}: $!";
  { local $/; $content = <$fh>; }
  is( $content, <<EOF, 'content in config' );
++<<<<<<< HEAD:t/aliases.t
 +
 +[alias]
 +	pull -a = pull --all
 +	pull -l = pull --local
++=======
+ alias pull -l = pull --local
+ alias foo bar = bar baz
+ alias pull -a = pull --all
++>>>>>>> master:t/aliases.t
  EOF
  
 +# TODO: need tests for interactive alias editing

commit d5faf258c2229b64b731f983c6723d1247645c25
Author: Christine Spang <spang at mit.edu>
Date:   Mon Jun 22 10:40:17 2009 +0300

    More informative 'sd aliases --show'.

diff --git a/lib/Prophet/CLI/Command/Aliases.pm b/lib/Prophet/CLI/Command/Aliases.pm
index 27d7b3d..bb2e6ce 100644
--- a/lib/Prophet/CLI/Command/Aliases.pm
+++ b/lib/Prophet/CLI/Command/Aliases.pm
@@ -101,8 +101,9 @@ sub make_template {
 
     my $content = '';
    
-    $content .= "# Format: new_cmd = cmd\n"
-      unless $self->context->has_arg('show');
+    $content .= $self->context->has_arg('show') ?
+        "Active aliases for the current repository (including user-wide and global\naliases if not overridden):\n\n"
+        : "# Format: new_cmd = cmd\n";
 
     # get all settings records
     my $aliases = $self->app_handle->config->aliases;

commit 76646e0721480fdbb821b42c2805ca2e7a0c9e8d
Author: Christine Spang <spang at mit.edu>
Date:   Mon Jun 22 11:21:03 2009 +0300

    sd aliases displays by default. sd aliases edit edits.

diff --git a/lib/Prophet/CLI/Command/Aliases.pm b/lib/Prophet/CLI/Command/Aliases.pm
index bb2e6ce..e6748df 100644
--- a/lib/Prophet/CLI/Command/Aliases.pm
+++ b/lib/Prophet/CLI/Command/Aliases.pm
@@ -22,11 +22,6 @@ sub run {
 
     my $config = $self->app_handle->config;
 
-    if ( $self->context->has_arg('show') ) {
-        print $template. "\n";
-        return;
-    }
-
     if ($self->has_arg('global')) {
         $self->config_filename($config->global_file);
     }
@@ -87,13 +82,18 @@ sub run {
         }
 
     }
-    else {
+    elsif ( $self->has_arg('edit') ) {
         my $done = 0;
 
         while ( !$done ) {
             $done = $self->try_to_edit( template => \$template );
         }
     }
+    else {
+        print $template. "\n";
+        return;
+    }
+
 }
 
 sub make_template {
@@ -101,9 +101,9 @@ sub make_template {
 
     my $content = '';
    
-    $content .= $self->context->has_arg('show') ?
-        "Active aliases for the current repository (including user-wide and global\naliases if not overridden):\n\n"
-        : "# Format: new_cmd = cmd\n";
+    $content .= $self->context->has_arg('edit') ?
+        "# Format: new_cmd = cmd\n"
+        : "Active aliases for the current repository (including user-wide and global\naliases if not overridden):\n\n";
 
     # get all settings records
     my $aliases = $self->app_handle->config->aliases;
diff --git a/lib/Prophet/CLI/Dispatcher.pm b/lib/Prophet/CLI/Dispatcher.pm
index 9332d56..b868f95 100644
--- a/lib/Prophet/CLI/Dispatcher.pm
+++ b/lib/Prophet/CLI/Dispatcher.pm
@@ -47,6 +47,7 @@ on [ ['show', 'display'] ]       => run_command("Show");
 on [ ['update', 'edit'] ]        => run_command("Update");
 on [ ['delete', 'del', 'rm'] ]   => run_command("Delete");
 on [ ['search', 'list', 'ls' ] ] => run_command("Search");
+on [ ['aliases', 'alias'] ]      => run_command('Aliases');
 
 on version  => run_command("Version");
 on init     => run_command("Init");
@@ -62,7 +63,7 @@ on log      => run_command("Log");
 on shell    => run_command("Shell");
 on export   => run_command('Export');
 on info     => run_command('Info');
-on aliases     => run_command('Aliases');
+on history  => run_command('History');
 
 on push => sub {
     my $self = shift;
@@ -89,14 +90,15 @@ on qr/^alias(?:es)?\s*(.*)/ => sub {
     elsif ( $arg =~ /=/ ) {
         $self->context->set_arg(set => $arg);
     }
+    elsif ( $arg =~ /^edit\b/ ) {
+        $self->context->set_arg(edit => 1);
+    }
     else {
         die 'no idea what you mean, sorry';
     }
     run( 'aliases', $self, @_ );
 };
 
-on history => run_command('History');
-
 sub run_command {
     my $name = shift;
     return sub {

commit 723b5f782014599fa53fdbc35f724b79161a3cd5
Author: Christine Spang <spang at mit.edu>
Date:   Mon Jun 22 13:16:23 2009 +0300

    Finish --user and --global flags for editing aliases.

diff --git a/lib/Prophet/CLI/Command/Aliases.pm b/lib/Prophet/CLI/Command/Aliases.pm
index e6748df..f3dc249 100644
--- a/lib/Prophet/CLI/Command/Aliases.pm
+++ b/lib/Prophet/CLI/Command/Aliases.pm
@@ -18,7 +18,6 @@ sub ARG_TRANSLATIONS { shift->SUPER::ARG_TRANSLATIONS(),  a => 'add', d => 'dele
 
 sub run {
     my $self     = shift;
-    my $template = $self->make_template;
 
     my $config = $self->app_handle->config;
 
@@ -29,6 +28,8 @@ sub run {
         $self->config_filename($config->user_file);
     }
 
+    my $template = $self->make_template;
+
     # add is the same as set
     if ( $self->context->has_arg('add') ) {
         $self->context->set_arg('set', $self->arg('add') )
@@ -102,11 +103,16 @@ sub make_template {
     my $content = '';
    
     $content .= $self->context->has_arg('edit') ?
-        "# Format: new_cmd = cmd\n"
-        : "Active aliases for the current repository (including user-wide and global\naliases if not overridden):\n\n";
+        "# Editing aliases in config file ".$self->config_filename."\n\n"
+        ."# Format: new_cmd = cmd\n"
+        : "Active aliases for the current repository (including user-wide and"
+        ." global\naliases if not overridden):\n\n";
 
-    # get all settings records
-    my $aliases = $self->app_handle->config->aliases;
+    # get aliases from the config file we're going to edit, or all of them if
+    # we're just displaying
+    my $aliases = $self->has_arg('edit') ?
+                  $self->app_handle->config->aliases( $self->config_filename )
+                : $self->app_handle->config->aliases;
 
     if ( $aliases ) {
         for my $key ( keys %$aliases ) {
@@ -138,7 +144,7 @@ sub process_template {
     my $updated = $args{edited};
     my ($config) = $self->parse_template($updated);
 
-    my $aliases = $self->app_handle->config->aliases;
+    my $aliases = $self->app_handle->config->aliases( $self->config_filename );
     my $c = $self->app_handle->config;
 
     my @added = grep { !$aliases->{$_} } sort keys %$config;
diff --git a/lib/Prophet/Config.pm b/lib/Prophet/Config.pm
index a15d409..5dd7a68 100644
--- a/lib/Prophet/Config.pm
+++ b/lib/Prophet/Config.pm
@@ -47,14 +47,43 @@ override global_file => sub {
 # grab all values in the 'alias' section and strip away the section name
 sub aliases {
     my $self = shift;
-
-    my %aliases = $self->get_regexp( key => '^alias\.' );
-
-    my %new_aliases = map {
-        my $alias = $_;
-        $alias =~ s/^alias\.//;
-        ( $alias => $aliases{$_} );
-    } keys %aliases;
+    my $file = shift;
+
+    my %new_aliases;
+    if ( $file ) {
+        # parse the given config file with parse_content and use the
+        # callbacks to add to an array
+        my $content = Prophet::Util->slurp( $file );
+        $self->parse_content(
+            content => $content,
+            callback => sub {
+                my %args = @_;
+                return unless defined $args{name};
+                if ( $args{section} eq 'alias' ) {
+                    $new_aliases{$args{name}} = $args{value};
+                }
+            },
+            # Most of the time this error sub won't get triggered since
+            # Prophet loads the config file whenever it first tries to use
+            # a value from the config file, and errors are detected at that
+            # point. This always happens before this since every command
+            # triggers alias processing. So this should really only explode
+            # if we're running a shell and the config file has changed
+            # in a bad way since we started up.
+            error => sub {
+                Config::GitLike::error_callback( @_, filename => $file );
+            },
+        );
+    }
+    else {
+        my %aliases = $self->get_regexp( key => '^alias\.' );
+
+        %new_aliases = map {
+            my $alias = $_;
+            $alias =~ s/^alias\.//;
+            ( $alias => $aliases{$_} );
+        } keys %aliases;
+    }
 
     return wantarray ? %new_aliases : \%new_aliases;
 }
@@ -142,12 +171,15 @@ Both constructor arguments are required.
 The replica-specific configuration file, or the configuration file given
 by C<PROPHET_APP_CONFIG> if that environmental variable is set.
 
-=head2 aliases
+=head2 aliases( $config_filename )
 
 A convenience method that gets you a hash (or a hashref, depending on context)
 of all currently defined aliases. (Basically, every entry in the 'alias'
 section of the config file.)
 
+If a filename is passed in, this method will only return the aliases that
+are defined in that particular config file.
+
 =head2 sources
 
 A convenience method that gets you a hash (or a hashref, depending on context)

commit 032770b54b43a734cf4991d3663a642a383ed909
Author: Christine Spang <spang at mit.edu>
Date:   Mon Jun 22 14:53:49 2009 +0300

    Don't interpret anything in a command alias as a regex metacharacter.

diff --git a/lib/Prophet/CLI.pm b/lib/Prophet/CLI.pm
index f06a0a2..cbf0e75 100644
--- a/lib/Prophet/CLI.pm
+++ b/lib/Prophet/CLI.pm
@@ -114,7 +114,7 @@ sub _command_matches_alias {
     my $cmd   = shift;
     my $alias = shift;
     my $dispatch_to = shift;;
-    if ( $cmd =~ /^$alias\s*(.*)$/ ) {
+    if ( $cmd =~ /^\Q$alias\E\s*(.*)$/ ) {
         no strict 'refs';
 
         my $rest = $1;

commit 849abbb6f4826e24e2157ac0b5d62a2a17eacd7b
Author: Christine Spang <spang at mit.edu>
Date:   Mon Jun 22 15:11:17 2009 +0300

    Update aliases.t for new config API (again)

diff --git a/lib/Prophet/CLI/Command/Aliases.pm b/lib/Prophet/CLI/Command/Aliases.pm
index f3dc249..56a707b 100644
--- a/lib/Prophet/CLI/Command/Aliases.pm
+++ b/lib/Prophet/CLI/Command/Aliases.pm
@@ -114,11 +114,15 @@ sub make_template {
                   $self->app_handle->config->aliases( $self->config_filename )
                 : $self->app_handle->config->aliases;
 
-    if ( $aliases ) {
+    if ( %$aliases ) {
         for my $key ( keys %$aliases ) {
             $content .= "$key = $aliases->{$key}\n";
         }
     }
+    else {
+        $content = "No aliases for the current repository.\n";
+    }
+
 
     return $content;
 }
@@ -169,6 +173,10 @@ sub process_template {
         );
     };
     # if we fail, prompt the user to re-edit
+
+    # one of the few ways to trigger this is to try to set a variable
+    # that starts with a [ character
+
     # TODO: this doesn't really work correctly.
     # Also, handle_template_errors gives messages that are very
     # much tailored towards SD's ticket editing facility.
diff --git a/t/aliases.t b/t/aliases.t
index 9aa3223..57859b3 100644
--- a/t/aliases.t
+++ b/t/aliases.t
@@ -2,7 +2,7 @@
 #
 use warnings;
 use strict;
-use Prophet::Test tests => 19;
+use Prophet::Test tests => 18;
 use File::Temp qw/tempfile/;
 
 $ENV{'PROPHET_REPO'} = $Prophet::Test::REPO_BASE . '/repo-' . $$;
@@ -23,7 +23,7 @@ is_deeply( scalar $config->aliases, {}, 'initial alias is empty' );
 my @cmds = (
     {
         cmd => [ 'show' ],
-        output  => qr/^\s*$/,
+        output  => qr/^No aliases for the current repository.\n$/,
         comment => 'show empty aliases',
     },
 
@@ -68,12 +68,7 @@ my @cmds = (
     },
     {
         cmd => [ 'show' ],
-        output  => qr/alias pull -a = pull --all/s,
-        comment => 'show',
-    },
-    {
-        cmd => [ 'show' ],
-        output  => qr/alias pull -l = pull --local/s,
+        output  => qr/Active aliases for the current repository \(including user-wide and global\naliases if not overridden\):\n\npull -l = pull --local\npull -a = pull --all/s,
         comment => 'show',
     },
     {
@@ -84,7 +79,7 @@ my @cmds = (
     {
         cmd => [ 'foo', 'bar', '=', 'bar',  'baz' ],
         output  => qr/alias 'foo bar = bar baz' isn't changed, won't update/,
-        comment => 'readd alias foo bar',
+        comment => 'read alias foo bar',
     },
     {
         cmd => [ 'delete', 'foo', 'bar' ],
@@ -126,16 +121,11 @@ open my $fh, '<', $ENV{'PROPHET_APP_CONFIG'}
   or die "failed to open $ENV{'PROPHET_APP_CONFIG'}: $!";
 { local $/; $content = <$fh>; }
 is( $content, <<EOF, 'content in config' );
-<<<<<<< HEAD:t/aliases.t
 
 [alias]
 	pull -a = pull --all
 	pull -l = pull --local
-=======
-alias pull -l = pull --local
-alias foo bar = bar baz
-alias pull -a = pull --all
->>>>>>> master:t/aliases.t
+	foo bar = bar baz
 EOF
 
 # TODO: need tests for interactive alias editing

commit fd24abf70b083688a5f0349826541a8b80503c8a
Author: Christine Spang <spang at mit.edu>
Date:   Mon Jun 22 16:43:50 2009 +0300

    Fix displaying of errors if set fails.

diff --git a/lib/Prophet/CLI/Command/Aliases.pm b/lib/Prophet/CLI/Command/Aliases.pm
index 56a707b..74df7f1 100644
--- a/lib/Prophet/CLI/Command/Aliases.pm
+++ b/lib/Prophet/CLI/Command/Aliases.pm
@@ -14,6 +14,12 @@ has config_filename => (
     },
 );
 
+has old_errors => (
+    is => 'rw',
+    isa => 'Str',
+    default => '',
+);
+
 sub ARG_TRANSLATIONS { shift->SUPER::ARG_TRANSLATIONS(),  a => 'add', d => 'delete', s => 'show' };
 
 sub run {
@@ -172,23 +178,24 @@ sub process_template {
             \@to_set,
         );
     };
-    # if we fail, prompt the user to re-edit
 
-    # one of the few ways to trigger this is to try to set a variable
+    # if we fail, prompt the user to re-edit
+    #
+    # one of the few ways to trigger this is to try to create an alias
     # that starts with a [ character
-
-    # TODO: this doesn't really work correctly.
-    # Also, handle_template_errors gives messages that are very
-    # much tailored towards SD's ticket editing facility.
-    # Should genericise that.
     if ($@) {
-        warn $@;
-        return $self->handle_template_errors(
+        chomp $@;
+        my $error = "# Error: '$@'";
+        $self->handle_template_errors(
             rtype => 'aliases',
             template_ref => $args{template},
             bad_template => $args{edited},
-            error => "$@",
+            errors_pattern => '',
+            error => $error,
+            old_errors => $self->old_errors,
         );
+        $self->old_errors($error);
+        return 0;
     }
     # otherwise, print out what changed and return happily
     else {
diff --git a/lib/Prophet/CLI/TextEditorCommand.pm b/lib/Prophet/CLI/TextEditorCommand.pm
index 3068596..2dd4340 100644
--- a/lib/Prophet/CLI/TextEditorCommand.pm
+++ b/lib/Prophet/CLI/TextEditorCommand.pm
@@ -88,27 +88,42 @@ template (given by the arg C<bad_template> prefixed with the error messages
 given in the C<error> arg. If an errors section already exists in the
 template, it is replaced with an errors section containing the new errors.
 
+If the template you are editing is not section-based, you can override what
+will be prepended to the template by passing in the C<errors_pattern>
+argument, and passing in C<old_errors> if a template errors out repeatedly
+and there are old errors in the template that need to be replaced.
+
 Other arguments are: C<rtype>: the type of the record being edited. All
-arguments are required.
+arguments except overrides (C<errors_pattern> and C<old_errors> are
+required.
 
 =cut
 
 sub handle_template_errors {
     my $self = shift;
     my %args = validate( @_, { error => 1, template_ref => 1,
-                               bad_template => 1, rtype => 1 } );
-    my $errors_pattern = "=== errors in this $args{rtype} ===";
+                               bad_template => 1, rtype => 1,
+                               errors_pattern => 0, old_errors => 0 } );
+    my $errors_pattern = defined $args{errors_pattern}
+                       ? $args{errors_pattern}
+                       : "=== errors in this $args{rtype} ===";
 
     $self->prompt_Yn("Whoops, an error occurred processing your $args{rtype}.\nTry editing again? (Errors will be shown.)") || die "Aborted.\n";
 
-    # if the bad template already has an errors section in it, remove it
-    $args{bad_template} =~ s/$errors_pattern.*?\n(?==== .*? ===\n)//s;
+    # template is section-based
+    if ( !defined $args{old_errors} ) {
+        # if the bad template already has an errors section in it, remove it
+        $args{bad_template} =~ s/$errors_pattern.*?\n(?==== .*? ===\n)//s;
+    }
+    # template is not section-based: we allow passing in the old error to kill
+    else {
+        $args{bad_template} =~ s/\Q$args{old_errors}\E\n\n\n//;
+    }
 
     ${ $args{'template_ref'} }
-        = "$errors_pattern\n\n"
-        . $args{error} . "\n\n"
-        . 'You can bypass validation for a property by appending a ! to it.'
-        . "\n\n\n" . $args{bad_template};
+        = $errors_pattern ? "$errors_pattern\n\n" : ''
+        . $args{error} . "\n\n\n"
+        . $args{bad_template};
     return 0;
 }
 

commit 7fde2443ca389c60ab8cb294854df61efd90e175
Author: Christine Spang <spang at mit.edu>
Date:   Mon Jun 22 23:09:58 2009 +0300

    Add a newline after getting output.

diff --git a/lib/Prophet/CLI/Command.pm b/lib/Prophet/CLI/Command.pm
index ee9a3f2..089f566 100644
--- a/lib/Prophet/CLI/Command.pm
+++ b/lib/Prophet/CLI/Command.pm
@@ -229,6 +229,7 @@ sub prompt_Yn {
 
     my $a = <STDIN>;
     chomp $a;
+    print "\n";
 
     return 1 if $a =~ /^(|y|yes)$/i;
     return 0;

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



More information about the Bps-public-commit mailing list