[Bps-public-commit] r16847 - Prophet/trunk/lib/Prophet/CLI

jesse at bestpractical.com jesse at bestpractical.com
Sat Nov 15 20:44:41 EST 2008


Author: jesse
Date: Sat Nov 15 20:44:40 2008
New Revision: 16847

Modified:
   Prophet/trunk/lib/Prophet/CLI/Dispatcher.pm

Log:
* snapshot

Modified: Prophet/trunk/lib/Prophet/CLI/Dispatcher.pm
==============================================================================
--- Prophet/trunk/lib/Prophet/CLI/Dispatcher.pm	(original)
+++ Prophet/trunk/lib/Prophet/CLI/Dispatcher.pm	Sat Nov 15 20:44:40 2008
@@ -1,8 +1,21 @@
 package Prophet::CLI::Dispatcher;
 use Path::Dispatcher::Declarative -base;
 use Moose;
+use MooseX::ClassAttribute;
+use MooseX::AttributeHelpers;
+
 with 'Prophet::CLI::Parameters';
 
+class_has command_prefixes => (
+    isa => 'ArrayRef',
+    metaclass => 'Collection::Array',
+    is => 'rw',
+    default => sub { ['Prophet::CLI::Command'] },
+    provides => {
+        unshift => 'add_command_prefix'
+    }
+);
+
 # "ticket display $ID" -> "ticket display --id=$ID"
 on qr{^ (.*) \s+ ( \d+ | [A-Z0-9]{36} ) $ }x => sub {
     my $self = shift;
@@ -10,6 +23,12 @@
     run($1, $self, @_);
 };
 
+on '' => sub {
+    if ($self->context->has_arg('version')) { run_command("Version") }
+    elsif( $self->context->has_arg('help') ){ run_command("Help") }
+    else { run_command('Shell') }
+};
+
 on [ ['create', 'new'] ]         => run_command("Create");
 on [ ['show', 'display'] ]       => run_command("Show");
 on [ ['update', 'edit'] ]        => run_command("Update");
@@ -54,10 +73,8 @@
 
 sub run_command {
     my $name = shift;
-
     return sub {
         my $self = shift;
-
         my %constructor_args = (
             cli      => $self->cli,
             context  => $self->context,
@@ -84,7 +101,8 @@
 sub class_names {
     my $self = shift;
     my $command = shift;
-    return "Prophet::CLI::Command::$command";
+    return map { $_."::".$command } @{$self->command_prefixes};
+
 }
 
 __PACKAGE__->meta->make_immutable;



More information about the Bps-public-commit mailing list