[Bps-public-commit] r16448 - in Prophet/branches/class-dispatch: .

sartak at bestpractical.com sartak at bestpractical.com
Tue Oct 21 14:45:23 EDT 2008


Author: sartak
Date: Tue Oct 21 14:45:22 2008
New Revision: 16448

Modified:
   Prophet/branches/class-dispatch/   (props changed)
   Prophet/branches/class-dispatch/lib/Prophet/CLI/Dispatcher.pm

Log:
 r74312 at onn:  sartak | 2008-10-21 14:45:15 -0400
 The entire class-based dispatcher, some short commands don't run classes


Modified: Prophet/branches/class-dispatch/lib/Prophet/CLI/Dispatcher.pm
==============================================================================
--- Prophet/branches/class-dispatch/lib/Prophet/CLI/Dispatcher.pm	(original)
+++ Prophet/branches/class-dispatch/lib/Prophet/CLI/Dispatcher.pm	Tue Oct 21 14:45:22 2008
@@ -1,70 +1,63 @@
 package Prophet::CLI::Dispatcher;
-use strict;
-use warnings;
 use Path::Dispatcher::Declarative -base;
+use Moose;
+with 'Prophet::CLI::Parameters';
 
-# "ticket display $ID" -> "ticket display --id=$ID"
-on qr{ (.*) \s+ ( \d+ | [A-Z0-9]{36} ) $ }x => sub {
-    my %args = @_;
-    $args{cli}->set_arg(id => $2);
-    run($1, %args);
-};
-
-on qr{^(\w+)} => sub {
-    my %args = @_;
-
-    my $cmd = __PACKAGE__->resolve_builtin_aliases($1);
+on [ ['create', 'new'] ]         => command("Create");
+on [ ['show', 'display'] ]       => command("Show");
+on [ ['update', 'edit'] ]        => command("Update");
+on [ ['delete', 'del', 'rm'] ]   => command("Delete");
+on [ ['search', 'list', 'ls' ] ] => command("Search");
+
+on merge   => command("Merge");
+on pull    => command("Pull");
+on publish => command("Publish");
+on server  => command("Server");
+on config  => command("Config");
+on log     => command("Log");
+on shell   => command("Shell");
 
-    my @possible_classes = (
-        ("Prophet::CLI::Command::" . ucfirst lc $cmd),
-        "Prophet::CLI::Command::NotFound",
-    );
-
-    my $cli = $args{cli};
-
-    for my $class (@possible_classes) {
-        if ($cli->_try_to_load_cmd_class($class)) {
-            return $args{got_command}->($class);
-        }
-    }
+on export => sub {
+    my $self = shift;
+    $self->cli->handle->export_to(path => $self->context->arg('path'));
 };
 
-on qr{^\s*$} => sub {
-    run(__PACKAGE__->default_command, @_);
+on push => sub {
+    my $self = shift;
 
-};
+    die "Please specify a --to.\n" if !$self->context->has_arg('to');
 
-my %CMD_MAP = (
-    ls      => 'search',
-    new     => 'create',
-    edit    => 'update',
-    rm      => 'delete',
-    del     => 'delete',
-    list    => 'search',
-    display => 'show',
-);
+    $self->context->set_arg(from => $self->cli->app_handle->default_replica_type.":file://".$self->cli->handle->fs_root);
+    $self->context->set_arg(db_uuid => $self->cli->handle->db_uuid);
+    run('merge', $self, @_);
+};
 
-sub resolve_builtin_aliases {
+on history => sub {
     my $self = shift;
-    my @cmds = @_;
 
-    if (my $replacement = $CMD_MAP{ lc $cmds[-1] }) {
-        $cmds[-1] = $replacement;
-    }
+    $self->context->require_uuid;
+    my $record = $self->context->_load_record;
+    $self->record($record);
+    print $record->history_as_string;
+};
 
-    @cmds = map { ucfirst lc } @cmds;
+sub command {
+    my $name = shift;
 
-    return wantarray ? @cmds : $cmds[-1];
+    return sub {
+        my $self = shift;
+        my $class = $self->class_name($name);
+        $class->new(cli => $self->cli)->run;
+    };
 }
 
-=head2 default_command
-
-Returns the "default" command for use when no arguments were specified on the
-command line. In Prophet, it's "shell" but your subclass can change that.
-
-=cut
+sub class_name {
+    my $command = shift;
+    return "Prophet::CLI::Command::$command";
+}
 
-sub default_command { "shell" }
+__PACKAGE__->meta->make_immutable;
+no Moose;
 
 1;
 



More information about the Bps-public-commit mailing list