[Bps-public-commit] r11951 - in sd/trunk: bin

jesse at bestpractical.com jesse at bestpractical.com
Tue Apr 29 14:25:13 EDT 2008


Author: jesse
Date: Tue Apr 29 14:25:12 2008
New Revision: 11951

Modified:
   sd/trunk/bin/sd
   sd/trunk/t/sd-hm.t
   sd/trunk/t/sd-rt-hm.t
   sd/trunk/t/sd-rt.t
   sd/trunk/t/sd-validation.t

Log:
* Update SD to use the new Prophet App command infrastructure


Modified: sd/trunk/bin/sd
==============================================================================
--- sd/trunk/bin/sd	(original)
+++ sd/trunk/bin/sd	Tue Apr 29 14:25:12 2008
@@ -6,16 +6,21 @@
 $ENV{'PROPHET_REPO'} = $ENV{'SD_REPO'} || $ENV{'HOME'}.'/.svb';
 
 use Prophet::CLI;
-my $CLI = Prophet::CLI->new( { app_class => 'App::SD' } );
-$CLI->register_types('App::SD::Model' => qw(ticket comment));
+my $cli = Prophet::CLI->new( { app_class => 'App::SD' } );
+$cli->run_one_command;
 
-my $command = shift @ARGV;
 
-my $func = main->can('cmd_'.$command) || main->can('cmd_help');
-$func->();
 
 
-sub cmd_help {
+package App::SD::CLI::Command;
+use base qw/Prophet::CLI::Command/;
+
+
+
+package App::SD::CLI::Command::Help;
+use base qw/App::SD::CLI::Command/;
+
+sub run {
 
 print <<EOF
 
@@ -33,14 +38,20 @@
 
 }
 
-sub cmd_details {
-    $CLI->do_show;
-    cmd_comments($CLI->uuid);
+
+package App::SD::CLI::Command::Details;
+use base qw/App::SD::CLI::Command/;
+sub run {
+    App::SD::Command::Ticket::Show->run();
+    App::SD::Command::Comments->run();
 }
 
-sub cmd_comments {
-    my ($ticket) = @ARGV;
-    my $record = App::SD::Model::Ticket->new( { handle => $CLI->app_handle->handle } );
+package App::SD::CLI::Command::Comments;
+use base qw/App::SD::CLI::Command/;
+sub run {
+    my $self = shift;
+    my ($ticket) = $self->args->{'uuid'};
+    my $record = App::SD::Model::Ticket->new( { handle => $self->app_handle->handle } );
     $record->load( uuid => $ticket );
     print "id: " . $record->uuid . "\n";
     unless (@{$record->comments}) {
@@ -55,59 +66,30 @@
 
 }
 
-sub cmd_push {
-
-    # Trivial first pass:
-#    only support pull
-    my $url = shift @ARGV;
 
+package App::SD::CLI::Command::Merge;
+use base qw/App::SD::CLI::Command Prophet::CLI::Command::Merge/;
 
+package App::SD::CLI::Command::Push;
+use base qw/App::SD::CLI::Command::Merge/;
 
+sub run {
+    my $self = shift; 
     local $ENV{PROPHET_RESOLVER} = 'Prompt';
-    my %args =  ( to => $url, from => $ENV{'PROPHET_REPLICA_TYPE'}.":file://".$CLI->app_handle->handle->fs_root );
-
-    $CLI->args(\%args);
-    $CLI->do_merge();
-
-
-
-return;
-    my $source = Prophet::Replica->new( { url => $ENV{'PROPHET_REPLICA_TYPE'}.':file://'.$CLI->app_handle->fs_root } );
-    my $target = Prophet::Replica->new( { url => $url });
-    my $changesets = $source->new_changesets_for($target);
-    warn Dumper($changesets); use Data::Dumper;
-
-
-    $target->record_changeset_integration( $_->original_source_uuid, $_->original_sequence_no) for @$changesets;
-
+    bless $self, 'App::SD::CLI::Command::Merge';
+    $self->args( {to => $self->args->{'to'}, from => $ENV{'PROPHET_REPLICA_TYPE'}.":file://".$self->app_handle->handle->fs_root });
+    $self->run; 
 }
 
-sub cmd_pull {
-    my $url = shift @ARGV;
-    local $ENV{PROPHET_RESOLVER} = 'Prompt';
-    my %args =  ( from => $url, to => $ENV{'PROPHET_REPLICA_TYPE'}.":file://".$CLI->app_handle->handle->fs_root );
+package App::SD::CLI::Command::Pull;
+use base qw/App::SD::CLI::Command::Merge/;
 
-    $CLI->args(\%args);
-    $CLI->do_merge();
-        
-#         [ 'merge', '--prefer', 'to', '--from', repo_uri_for($from), '--to', repo_uri_for( $self->name ) ],
+sub run {
+    my $self = shift; 
+    local $ENV{PROPHET_RESOLVER} = 'Prompt';
+    bless $self, 'App::SD::CLI::Command::Merge';
+    $self->args({  from => $self->args->{'from'}, 
+                   to => $ENV{'PROPHET_REPLICA_TYPE'}.":file://".$cli->app_handle->handle->fs_root });
+    $self->run; 
 }
 
-=begin comment
-    # Trivial first pass:
-    
-    
-=end comment
-
-
-
-# svb ticket --create --owner foo at bar --subject hate --status new --comment "wtf svb!"
-# svb ticket --update <id> --status resolved
-# svb ticket --list <regex>
-# svb ticket --show <id>
-
-# svb pull <url>
-# svb push <url>
-# svb pull http://<rt url>
-# svb push http://<rt url>
-

Modified: sd/trunk/t/sd-hm.t
==============================================================================
--- sd/trunk/t/sd-hm.t	(original)
+++ sd/trunk/t/sd-hm.t	Tue Apr 29 14:25:12 2008
@@ -42,23 +42,23 @@
 
 my $sd_hm_url = "hm:$URL";
 warn $URL;
-eval { ( $ret, $out, $err ) = run_script( 'sd', [ 'pull', $sd_hm_url ] ) };
+eval { ( $ret, $out, $err ) = run_script( 'sd', [ 'pull', '--from', $sd_hm_url ] ) };
 diag $err;
 
 my ( $yatta_uuid, $flyman_uuid );
-run_output_matches( 'sd', [ 'ticket', '--list', '--regex', '.' ], [qr/(.*?)(?{ $flyman_uuid = $1 }) Fly Man (.*)/] );
+run_output_matches( 'sd', [ 'ticket', 'list', '--regex', '.' ], [qr/(.*?)(?{ $flyman_uuid = $1 }) Fly Man (.*)/] );
 
 $task->set_summary('Crash Man');
 
-( $ret, $out, $err ) = run_script( 'sd', [ 'pull', $sd_hm_url ] );
+( $ret, $out, $err ) = run_script( 'sd', [ 'pull', '--from', $sd_hm_url ] );
 
-run_output_matches( 'sd', [ 'ticket', '--list', '--regex', '.' ], [qr"$flyman_uuid Crash Man (.*)"] );
+run_output_matches( 'sd', [ 'ticket', 'list', '--regex', '.' ], [qr"$flyman_uuid Crash Man (.*)"] );
 
-( $ret, $out, $err ) = run_script( 'sd', [ 'ticket', '--show', '--uuid', $flyman_uuid ] );
+( $ret, $out, $err ) = run_script( 'sd', [ 'ticket', 'show', '--uuid', $flyman_uuid ] );
 
 run_output_matches(
     'sd',
-    [ 'ticket', '--create', '--summary', 'YATTA', '--status', 'new' ],
+    [ 'ticket', 'create', '--summary', 'YATTA', '--status', 'new' ],
     [qr/Created ticket (.*)(?{ $yatta_uuid = $1 })/]
 );
 
@@ -66,30 +66,30 @@
 
 run_output_matches(
     'sd',
-    [ 'ticket', '--list', '--regex', '.' ],
+    [ 'ticket', 'list', '--regex', '.' ],
     [   sort "$yatta_uuid YATTA new",
         "$flyman_uuid Crash Man (no status)",    # XXX: or whatever status captured previously
     ]
 );
 
-( $ret, $out, $err ) = run_script( 'sd', [ 'push', $sd_hm_url ] );
+( $ret, $out, $err ) = run_script( 'sd', [ 'push','--to', $sd_hm_url ] );
 diag $err;
 ok( $task->load_by_cols( summary => 'YATTA' ) );
 
-( $ret, $out, $err ) = run_script( 'sd', [ 'pull', $sd_hm_url ] );
+( $ret, $out, $err ) = run_script( 'sd', [ 'pull', '--from',$sd_hm_url ] );
 
 run_output_matches(
     'sd',
-    [ 'ticket',                     '--list', '--regex', '.' ],
+    [ 'ticket',                     'list', '--regex', '.' ],
     [ sort "$yatta_uuid YATTA new", "$flyman_uuid Crash Man (no status)", ]
 );
 
 $task->set_summary('KILL');
 
-( $ret, $out, $err ) = run_script( 'sd', [ 'pull', $sd_hm_url ] );
+( $ret, $out, $err ) = run_script( 'sd', [ 'pull', '--from', $sd_hm_url ] );
 
 run_output_matches(
     'sd',
-    [ 'ticket',                    '--list', '--regex', '.' ],
+    [ 'ticket',                    'list', '--regex', '.' ],
     [ sort "$yatta_uuid KILL new", "$flyman_uuid Crash Man (no status)", ]
 );

Modified: sd/trunk/t/sd-rt-hm.t
==============================================================================
--- sd/trunk/t/sd-rt-hm.t	(original)
+++ sd/trunk/t/sd-rt-hm.t	Tue Apr 29 14:25:12 2008
@@ -81,31 +81,31 @@
 # now the tests, bob syncs with rt, alice syncs with hm
 as_alice {
     local $ENV{SD_REPO} = $ENV{'PROPHET_REPO'};
-    ( $ret, $out, $err ) = run_script( 'sd', [ 'pull', $sd_hm_url ] );
+    ( $ret, $out, $err ) = run_script( 'sd', [ 'pull', '--from', $sd_hm_url ] );
     diag($err) if ($err);
-    run_output_matches( 'sd', [ 'ticket', '--list', '--regex', '.' ], [qr/(.*?)(?{ $yatta_uuid = $1 }) YATTA .*/] );
+    run_output_matches( 'sd', [ 'ticket', 'list', '--regex', '.' ], [qr/(.*?)(?{ $yatta_uuid = $1 }) YATTA .*/] );
 };
 
 as_bob {
     local $ENV{SD_REPO} = $ENV{'PROPHET_REPO'};
-    run_output_matches( 'sd', [ 'ticket', '--list', '--regex', '.' ], [] );
+    run_output_matches( 'sd', [ 'ticket', 'list', '--regex', '.' ], [] );
 
     diag("Bob pulling from RT");
-    ( $ret, $out, $err ) = run_script( 'sd', [ 'pull', $sd_rt_url ] );
+    ( $ret, $out, $err ) = run_script( 'sd', [ 'pull', '--from', $sd_rt_url ] );
     diag($err) if ($err);
-    run_output_matches( 'sd', [ 'ticket', '--list', '--regex', '.' ], [qr/(.*?)(?{ $flyman_uuid = $1 }) Fly Man new/] );
+    run_output_matches( 'sd', [ 'ticket', 'list', '--regex', '.' ], [qr/(.*?)(?{ $flyman_uuid = $1 }) Fly Man new/] );
 
     diag("Bob pulling from alice");
-    ( $ret, $out, $err ) = run_script( 'sd', [ 'pull', repo_uri_for('alice') ] );
+    ( $ret, $out, $err ) = run_script( 'sd', [ 'pull', '--from', repo_uri_for('alice') ] );
     run_output_matches(
         'sd',
-        [ 'ticket',                             '--list', '--regex', '.' ],
+        [ 'ticket',                             'list', '--regex', '.' ],
         [ sort "$yatta_uuid YATTA (no status)", "$flyman_uuid Fly Man new", ]
     );
 
 
     diag("Bob pushing to RT");
-    ( $ret, $out, $err ) = run_script( 'sd', [ 'push', $sd_rt_url ] );
+    ( $ret, $out, $err ) = run_script( 'sd', [ 'push', '--to', $sd_rt_url ] );
     diag($err) if ($err);
 
     # XXX: to check YATTA ticket created in RT.
@@ -113,17 +113,18 @@
 
 as_alice {
     local $ENV{SD_REPO} = $ENV{'PROPHET_REPO'};
-    ( $ret, $out, $err ) = run_script( 'sd', [ 'pull', repo_uri_for('bob') ] );
+    ( $ret, $out, $err ) = run_script( 'sd', [ 'pull', '--from', repo_uri_for('bob') ] );
     run_output_matches(
         'sd',
-        [ 'ticket',                             '--list', '--regex', '.' ],
+        [ 'ticket',                             'list', '--regex', '.' ],
         [ sort "$yatta_uuid YATTA (no status)", "$flyman_uuid Fly Man new", ]
     );
 
-    ( $ret, $out, $err ) = run_script( 'sd', [ 'push', $sd_rt_url ] );
+    ( $ret, $out, $err ) = run_script( 'sd', [ 'push', '--to', $sd_rt_url ] );
 
     ok( $task->load_by_cols( summary => 'Fly Man' ) );
 };
+
 exit(0);
 
 __END__
@@ -152,10 +153,10 @@
 
 diag $ticket->id;
 my ($ret, $out, $err);
-($ret, $out, $err) = run_script('sd', ['pull', $sd_rt_url]);
+($ret, $out, $err) = run_script('sd', ['pull', '--from', $sd_rt_url]);
 warn $err;
 my ($yatta_uuid, $flyman_uuid);
-run_output_matches('sd', ['ticket', '--list', '--regex', '.'], [qr/(.*?)(?{ $flyman_uuid = $1 }) Fly Man new/]);
+run_output_matches('sd', ['ticket', 'list', '--regex', '.'], [qr/(.*?)(?{ $flyman_uuid = $1 }) Fly Man new/]);
 
 
 RT::Client::REST::Ticket->new(
@@ -164,23 +165,23 @@
         status => 'open',
     )->store();
 
-($ret, $out, $err) = run_script('sd', ['pull', $sd_rt_url]);
+($ret, $out, $err) = run_script('sd', ['pull', '--from', $sd_rt_url]);
 
-run_output_matches('sd', ['ticket', '--list', '--regex', '.'], ["$flyman_uuid Fly Man open"]);
+run_output_matches('sd', ['ticket', 'list', '--regex', '.'], ["$flyman_uuid Fly Man open"]);
 
 # create from sd and push
 
-run_output_matches('sd', ['ticket', '--create', '--summary', 'YATTA', '--status', 'new'], [qr/Created ticket (.*)(?{ $yatta_uuid = $1 })/]);
+run_output_matches('sd', ['ticket', 'create', '--summary', 'YATTA', '--status', 'new'], [qr/Created ticket (.*)(?{ $yatta_uuid = $1 })/]);
 
 diag $yatta_uuid;
 
-run_output_matches('sd', ['ticket', '--list', '--regex', '.'],
+run_output_matches('sd', ['ticket', 'list', '--regex', '.'],
                    [ sort 
                     "$yatta_uuid YATTA new",
                      "$flyman_uuid Fly Man open",
                    ]);
 
-($ret, $out, $err) = run_script('sd', ['push', $sd_rt_url]);
+($ret, $out, $err) = run_script('sd', ['push', '--to', $sd_rt_url]);
 diag $err;
 my @tix = $rt->search(
         type  => 'ticket',
@@ -189,9 +190,9 @@
 
 ok(scalar @tix, 'YATTA pushed');
 
-($ret, $out, $err) = run_script('sd', ['pull', $sd_rt_url]);
+($ret, $out, $err) = run_script('sd', ['pull', '--from', $sd_rt_url]);
 
-run_output_matches('sd', ['ticket', '--list', '--regex', '.'],
+run_output_matches('sd', ['ticket', 'list', '--regex', '.'],
                    [ sort
                     "$yatta_uuid YATTA new",
                      "$flyman_uuid Fly Man open",
@@ -203,9 +204,9 @@
         status => 'stalled',
     )->store();
 
-($ret, $out, $err) = run_script('sd', ['pull', $sd_rt_url]);
+($ret, $out, $err) = run_script('sd', ['pull', '--from', $sd_rt_url]);
 
-run_output_matches('sd', ['ticket', '--list', '--regex', '.'],
+run_output_matches('sd', ['ticket', 'list', '--regex', '.'],
                    [ sort
                     "$yatta_uuid YATTA new",
                      "$flyman_uuid Fly Man stalled",
@@ -218,9 +219,9 @@
     )->store();
 
 warn "===> bad pull";
-($ret, $out, $err) = run_script('sd', ['pull', $sd_rt_url]);
+($ret, $out, $err) = run_script('sd', ['pull', '--from', $sd_rt_url]);
 diag $err;
-run_output_matches('sd', ['ticket', '--list', '--regex', '.'],
+run_output_matches('sd', ['ticket', 'list', '--regex', '.'],
                    [ sort
                     "$yatta_uuid YATTA open",
                      "$flyman_uuid Fly Man stalled",

Modified: sd/trunk/t/sd-rt.t
==============================================================================
--- sd/trunk/t/sd-rt.t	(original)
+++ sd/trunk/t/sd-rt.t	Tue Apr 29 14:25:12 2008
@@ -43,35 +43,34 @@
 )->store( text => "Ticket Comment" );
 
 my ( $ret, $out, $err );
-( $ret, $out, $err ) = run_script( 'sd', [ 'pull', $sd_rt_url ] );
+( $ret, $out, $err ) = run_script( 'sd', [ 'pull', '--from',  $sd_rt_url ] );
 my ( $yatta_uuid, $flyman_uuid );
-run_output_matches( 'sd', [ 'ticket', '--list', '--regex', '.' ], [qr/(.*?)(?{ $flyman_uuid = $1 }) Fly Man new/] );
-
+run_output_matches( 'sd', [ 'ticket', 'list', '--regex', '.' ], [qr/(.*?)(?{ $flyman_uuid = $1 }) Fly Man new/] );
 RT::Client::REST::Ticket->new(
     rt     => $rt,
     id     => $ticket->id,
     status => 'open',
 )->store();
 
-( $ret, $out, $err ) = run_script( 'sd', [ 'pull', $sd_rt_url ] );
+( $ret, $out, $err ) = run_script( 'sd', [ 'pull', '--from', $sd_rt_url ] );
 
-run_output_matches( 'sd', [ 'ticket', '--list', '--regex', '.' ], ["$flyman_uuid Fly Man open"] );
+run_output_matches( 'sd', [ 'ticket', 'list', '--regex', '.' ], ["$flyman_uuid Fly Man open"] );
 
 # create from sd and push
 
 run_output_matches(
     'sd',
-    [ 'ticket', '--create', '--summary', 'YATTA', '--status', 'new' ],
+    [ 'ticket', 'create', '--summary', 'YATTA', '--status', 'new' ],
     [qr/Created ticket (.*)(?{ $yatta_uuid = $1 })/]
 );
 
 run_output_matches(
     'sd',
-    [ 'ticket',                     '--list', '--regex', '.' ],
+    [ 'ticket',                     'list', '--regex', '.' ],
     [ sort "$yatta_uuid YATTA new", "$flyman_uuid Fly Man open", ]
 );
 
-( $ret, $out, $err ) = run_script( 'sd', [ 'push', $sd_rt_url ] );
+( $ret, $out, $err ) = run_script( 'sd', [ 'push', '--to', $sd_rt_url ] );
 my @tix = $rt->search(
     type  => 'ticket',
     query => "Subject='YATTA'"
@@ -79,11 +78,11 @@
 
 ok( scalar @tix, 'YATTA pushed' );
 
-( $ret, $out, $err ) = run_script( 'sd', [ 'pull', $sd_rt_url ] );
+( $ret, $out, $err ) = run_script( 'sd', [ 'pull', '--from', $sd_rt_url ] );
 
 run_output_matches(
     'sd',
-    [ 'ticket',                     '--list', '--regex', '.' ],
+    [ 'ticket',                     'list', '--regex', '.' ],
     [ sort "$yatta_uuid YATTA new", "$flyman_uuid Fly Man open", ]
 );
 
@@ -93,11 +92,11 @@
     status => 'stalled',
 )->store();
 
-( $ret, $out, $err ) = run_script( 'sd', [ 'pull', $sd_rt_url ] );
+( $ret, $out, $err ) = run_script( 'sd', [ 'pull', '--from', $sd_rt_url ] );
 
 run_output_matches(
     'sd',
-    [ 'ticket',                     '--list', '--regex', '.' ],
+    [ 'ticket',                     'list', '--regex', '.' ],
     [ sort "$yatta_uuid YATTA new", "$flyman_uuid Fly Man stalled", ]
 );
 
@@ -108,10 +107,10 @@
 )->store();
 
 warn "===> bad pull";
-( $ret, $out, $err ) = run_script( 'sd', [ 'pull', $sd_rt_url ] );
+( $ret, $out, $err ) = run_script( 'sd', [ 'pull', '--from', $sd_rt_url ] );
 run_output_matches(
     'sd',
-    [ 'ticket',                      '--list', '--regex', '.' ],
+    [ 'ticket',                      'list', '--regex', '.' ],
     [ sort "$yatta_uuid YATTA open", "$flyman_uuid Fly Man stalled", ]
 );
 

Modified: sd/trunk/t/sd-validation.t
==============================================================================
--- sd/trunk/t/sd-validation.t	(original)
+++ sd/trunk/t/sd-validation.t	Tue Apr 29 14:25:12 2008
@@ -14,18 +14,18 @@
 # create from sd and push
 my $yatta_uuid;
 run_output_matches( 'sd', [ 'ticket',
-    '--create', '--summary', 'YATTA', '--status', 'new' ],
+    'create', '--summary', 'YATTA', '--status', 'new' ],
     [qr/Created ticket (.*)(?{ $yatta_uuid = $1 })/]
 );
 
 run_output_matches( 'sd', [ 'ticket',  
-    '--list', '--regex', '.' ],
+    'list', '--regex', '.' ],
     [ sort "$yatta_uuid YATTA new"]
 );
 
 
 is_script_output( 'sd', [ 'ticket',  
-    '--update', '--uuid', $yatta_uuid, '--status', 'super'
+    'update', '--uuid', $yatta_uuid, '--status', 'super'
     ],
    [undef],  # stdout
     [qr/Validation error for 'status': 'super' is not a valid status/], # stderr
@@ -33,13 +33,13 @@
 );
 
 run_output_matches( 'sd', [ 'ticket',  
-    '--list', '--regex', '.' ],
+    'list', '--regex', '.' ],
     [ sort "$yatta_uuid YATTA new"]
 );
 
 
 is_script_output( 'sd', [ 'ticket',  
-    '--update', '--uuid', $yatta_uuid, '--status', 'stalled'
+    'update', '--uuid', $yatta_uuid, '--status', 'stalled'
     ],
    [qr/ticket $yatta_uuid updated./], # stdout
    [], # stderr
@@ -48,27 +48,27 @@
 );
 
 run_output_matches( 'sd', [ 'ticket',  
-    '--list', '--regex', '.' ],
+    'list', '--regex', '.' ],
     [ sort "$yatta_uuid YATTA stalled"]
 );
 
 
 my $sylar_uuid;
 is_script_output( 'sd', [ 'ticket',
-    '--create', '--summary', 'Sylar!', '--status', 'evil' ],
+    'create', '--summary', 'Sylar!', '--status', 'evil' ],
     [undef],
     [qr/Validation error for 'status': 'evil' is not a valid status/],
     "Sylar can't create an eeevil ticket"
 );
 
 run_output_matches( 'sd', [ 'ticket',  
-    '--list', '--regex', '.' ],
+    'list', '--regex', '.' ],
     [ sort "$yatta_uuid YATTA stalled"]
 );
 
 
 is_script_output( 'sd', [ 'ticket',  
-    '--update', '--uuid', $yatta_uuid, '--status', ''
+    'update', '--uuid', $yatta_uuid, '--status', ''
     ],
    [], # stdout
     [qr/Validation error for 'status': '' is not a valid status/], #stderr
@@ -78,7 +78,7 @@
 
 
 run_output_matches( 'sd', [ 'ticket',  
-    '--list', '--regex', '.' ],
+    'list', '--regex', '.' ],
     [ sort "$yatta_uuid YATTA stalled"]
 );
 



More information about the Bps-public-commit mailing list