[Bps-public-commit] r15488 - in Prophet/branches/dispatcher: lib/Prophet lib/Prophet/CLI

sartak at bestpractical.com sartak at bestpractical.com
Tue Aug 26 11:27:38 EDT 2008


Author: sartak
Date: Tue Aug 26 11:27:38 2008
New Revision: 15488

Modified:
   Prophet/branches/dispatcher/   (props changed)
   Prophet/branches/dispatcher/lib/Prophet/CLI.pm
   Prophet/branches/dispatcher/lib/Prophet/CLI/Dispatcher.pm

Log:
 r70381 at onn:  sartak | 2008-08-26 11:27:02 -0400
 Reinstitute the command mapping in the dispatcher


Modified: Prophet/branches/dispatcher/lib/Prophet/CLI.pm
==============================================================================
--- Prophet/branches/dispatcher/lib/Prophet/CLI.pm	(original)
+++ Prophet/branches/dispatcher/lib/Prophet/CLI.pm	Tue Aug 26 11:27:38 2008
@@ -98,16 +98,6 @@
 
 =cut
 
-our %CMD_MAP = (
-    ls      => 'search',
-    new     => 'create',
-    edit    => 'update',
-    rm      => 'delete',
-    del     => 'delete',
-    list    => 'search',
-    display => 'show',
-);
-
 =head2 dispatcher -> Class
 
 Returns the dispatcher used to dispatch command lines. You'll want to override

Modified: Prophet/branches/dispatcher/lib/Prophet/CLI/Dispatcher.pm
==============================================================================
--- Prophet/branches/dispatcher/lib/Prophet/CLI/Dispatcher.pm	(original)
+++ Prophet/branches/dispatcher/lib/Prophet/CLI/Dispatcher.pm	Tue Aug 26 11:27:38 2008
@@ -14,8 +14,10 @@
     my $cli = shift;
     my %args = @_;
 
+    my $cmd = __PACKAGE__->resolve_builtin_aliases($1);
+
     my @possible_classes = (
-        ("Prophet::CLI::Command::" . ucfirst lc $1),
+        ("Prophet::CLI::Command::" . ucfirst lc $cmd),
         "Prophet::CLI::Command::Notound",
     );
 
@@ -26,5 +28,26 @@
     }
 };
 
+my %CMD_MAP = (
+    ls      => 'search',
+    new     => 'create',
+    edit    => 'update',
+    rm      => 'delete',
+    del     => 'delete',
+    list    => 'search',
+    display => 'show',
+);
+
+sub resolve_builtin_aliases {
+    my $self = shift;
+    my @cmds = @_;
+
+    if (my $replacement = $CMD_MAP{ lc $cmds[-1] }) {
+        $cmds[-1] = $replacement;
+    }
+
+    return wantarray ? @cmds : $cmds[-1];
+}
+
 1;
 



More information about the Bps-public-commit mailing list