[Bps-public-commit] Prophet branch, config-gitlike, updated. 1285e73dd8ea3e9c3afd6daeaf1b89054227a76c
spang at bestpractical.com
spang at bestpractical.com
Thu Jul 2 11:56:04 EDT 2009
The branch, config-gitlike has been updated
via 1285e73dd8ea3e9c3afd6daeaf1b89054227a76c (commit)
from 9d08f73fc23894f580ad19a6132bdfcc93247183 (commit)
Summary of changes:
lib/Prophet/CLI/Command/Aliases.pm | 47 +++++++++++++++++++++++++++++++++
lib/Prophet/CLI/Dispatcher.pm | 51 +++++++-----------------------------
2 files changed, 57 insertions(+), 41 deletions(-)
- Log -----------------------------------------------------------------
commit 1285e73dd8ea3e9c3afd6daeaf1b89054227a76c
Author: Christine Spang <spang at mit.edu>
Date: Thu Jul 2 11:38:46 2009 -0400
Move aliases cli parsing logic into the Aliases command class
diff --git a/lib/Prophet/CLI/Command/Aliases.pm b/lib/Prophet/CLI/Command/Aliases.pm
index 43be982..51f922a 100644
--- a/lib/Prophet/CLI/Command/Aliases.pm
+++ b/lib/Prophet/CLI/Command/Aliases.pm
@@ -144,6 +144,53 @@ sub process_template {
}
}
+sub parse_cli_arg {
+ my $self = shift;
+ my ($cmd, $arg) = @_;
+
+ if ( $arg =~ /^show\b/ ) {
+ $self->context->set_arg(show => 1);
+ }
+ elsif ( $arg =~ /^edit\b/ ) {
+ $self->context->set_arg(edit => 1);
+ }
+ # arg *might* be quoted
+ elsif ( $arg =~ /^delete\s+"?([^"]+)"?/ ) {
+ $self->context->set_arg(delete => $1);
+ }
+ # prophet alias "foo bar" = "foo baz"
+ # prophet alias foo = bar
+ # prophet alias add foo bar = "bar baz"
+ # prophet alias add foo bar = bar baz
+ elsif ( $arg =~
+ /^(?:add |set )?\s*(?:(?:"([^"]+)"|([^"]+))\s+=\s+(?:"([^"]+)"|([^"]+)))$/ ) {
+ my ($orig, $new) = grep { defined } ($1, $2, $3, $4);
+ $orig = "'$orig'" if $cmd =~ /alias/ && $orig =~ /\./;
+ $self->context->set_arg(set => "$orig=$new");
+ }
+ # prophet alias "foo = bar"
+ # prophet alias "foo bar = foo baz"
+ elsif ( $arg =~ /^(?:add |set )?\s*"([^"]+=[^"]+)"$/ ) {
+ $self->context->set_arg(set => $1);
+ }
+ # alternate syntax (preferred):
+ # prophet alias "foo bar" "bar baz", prophet alias foo "bar baz",
+ # prophet alias foo bar, etc.
+ elsif ( $arg =~ /^(?:add |set )?\s*(?:"([^"]+)"|([^"\s]+))(?:\s+(?:"([^"]+)"|([^"\s]+)))?/ ) {
+ my ($orig, $new) = grep { defined } ($1, $2, $3, $4);
+ $orig = "'$orig'" if $cmd =~ /alias/ && $orig =~ /\./;
+ if ( $new ) {
+ $self->context->set_arg(set => "$orig=$new");
+ }
+ else {
+ $self->context->set_arg(set => $orig);
+ }
+ }
+ else {
+ die 'no idea what you mean, sorry';
+ }
+}
+
__PACKAGE__->meta->make_immutable;
no Any::Moose;
diff --git a/lib/Prophet/CLI/Dispatcher.pm b/lib/Prophet/CLI/Dispatcher.pm
index 16679d1..2e05e45 100644
--- a/lib/Prophet/CLI/Dispatcher.pm
+++ b/lib/Prophet/CLI/Dispatcher.pm
@@ -84,48 +84,17 @@ on qr/^(alias(?:es)?|config)?\s+(.*)/ => sub {
my $cmd = $1;
my $arg = $2;
- if ( $arg =~ /^show\b/ ) {
- $self->context->set_arg(show => 1);
- }
- elsif ( $arg =~ /^edit\b/ ) {
- $self->context->set_arg(edit => 1);
- }
- # arg *might* be quoted
- elsif ( $arg =~ /^delete\s+"?([^"]+)"?/ ) {
- $self->context->set_arg(delete => $1);
- }
- # prophet alias "foo bar" = "foo baz"
- # prophet alias foo = bar
- # prophet alias add foo bar = "bar baz"
- # prophet alias add foo bar = bar baz
- elsif ( $arg =~
- /^(?:add |set )?\s*(?:(?:"([^"]+)"|([^"]+))\s+=\s+(?:"([^"]+)"|([^"]+)))$/ ) {
- my ($orig, $new) = grep { defined } ($1, $2, $3, $4);
- $orig = "'$orig'" if $cmd =~ /alias/ && $orig =~ /\./;
- $self->context->set_arg(set => "$orig=$new");
- }
- # prophet alias "foo = bar"
- # prophet alias "foo bar = foo baz"
- elsif ( $arg =~ /^(?:add |set )?\s*"([^"]+=[^"]+)"$/ ) {
- $self->context->set_arg(set => $1);
- }
- # alternate syntax (preferred):
- # prophet alias "foo bar" "bar baz", prophet alias foo "bar baz",
- # prophet alias foo bar, etc.
- elsif ( $arg =~ /^(?:add |set )?\s*(?:"([^"]+)"|([^"\s]+))(?:\s+(?:"([^"]+)"|([^"\s]+)))?/ ) {
- my ($orig, $new) = grep { defined } ($1, $2, $3, $4);
- $orig = "'$orig'" if $cmd =~ /alias/ && $orig =~ /\./;
- if ( $new ) {
- $self->context->set_arg(set => "$orig=$new");
- }
- else {
- $self->context->set_arg(set => $orig);
- }
- }
- else {
- die 'no idea what you mean, sorry';
+ my @classes = $self->class_names('Aliases');
+ for my $class (@classes) {
+ Prophet::App->try_to_require($class) or next;
+ my $aliases_cmd = $class->new(
+ context => $self->context,
+ );
+ $aliases_cmd->parse_cli_arg($cmd, $arg);
+ return run( $cmd, $self, @_ );
}
- run( $cmd, $self, @_ );
+
+ die "Could not find 'Aliases' command class";
};
sub run_command {
-----------------------------------------------------------------------
More information about the Bps-public-commit
mailing list