[Bps-public-commit] SD branch, master, updated. 602082a0b0f68318067d1b5cab69aeaee40eb7d2

spang at bestpractical.com spang at bestpractical.com
Wed Aug 19 13:28:30 EDT 2009


The branch, master has been updated
       via  602082a0b0f68318067d1b5cab69aeaee40eb7d2 (commit)
       via  be1fb10a523b3b04ad3277aebdd25724cc9c163d (commit)
       via  4ea3da43f2dc7dbdb30bdc21cfd6c1124660b867 (commit)
       via  686b9fbfc794cf210ea78ad77261741b63a79afa (commit)
      from  1aeff8d9beb33221174253fca5e11a4d9d0748a8 (commit)

Summary of changes:
 bin/git-sd                          |    1 +
 contrib/sdticket.vim                |    4 +-
 lib/App/SD/CLI/Command/Clone.pm     |   22 ++++++
 lib/App/SD/CLI/Command/Init.pm      |   20 +++++
 lib/App/SD/CLI/Dispatcher.pm        |    2 +-
 lib/App/SD/CLI/NewReplicaCommand.pm |  136 +++++++++++++++++++++++++++++++++++
 6 files changed, 182 insertions(+), 3 deletions(-)
 create mode 100644 lib/App/SD/CLI/Command/Clone.pm
 create mode 100644 lib/App/SD/CLI/Command/Init.pm
 create mode 100644 lib/App/SD/CLI/NewReplicaCommand.pm

- Log -----------------------------------------------------------------
commit 686b9fbfc794cf210ea78ad77261741b63a79afa
Author: Christine Spang <spang at bestpractical.com>
Date:   Tue Aug 18 16:15:17 2009 +0100

    Add a newline after git config command for readability

diff --git a/bin/git-sd b/bin/git-sd
index cfd7f87..ade96bb 100755
--- a/bin/git-sd
+++ b/bin/git-sd
@@ -18,6 +18,7 @@ if [ -z "$replica" ]; then
     echo "Setting it to '$replica':"
     echo ""
     echo "  git config --add sd.local-replica $replica"
+    echo ""
     git config --add sd.local-replica "$replica"
 fi
 

commit 4ea3da43f2dc7dbdb30bdc21cfd6c1124660b867
Author: Christine Spang <spang at bestpractical.com>
Date:   Tue Aug 18 18:14:38 2009 +0100

    Use defaults in sdticket.vim when you're in the shell but have accidentally broken sd so it can't run to get the settings

diff --git a/contrib/sdticket.vim b/contrib/sdticket.vim
index 84c9bff..6c20d09 100644
--- a/contrib/sdticket.vim
+++ b/contrib/sdticket.vim
@@ -54,8 +54,8 @@ syn region sdColumn  start="^\w\+:\@="  end=":"
 " defaults
 let s:settings = system("sd settings")
 
-if s:settings =~ 'not found'
-  " user is running some wrapper script; use sd defaults
+if s:settings =~ '\(not found\)\|\(Compilation failed\)'
+  " user is running some wrapper script or sd is broken; use sd defaults
   syn keyword sdStatus new open closed stalled rejected
   syn keyword sdComponent core ui docs tests
   syn keyword sdMilestone alpha beta 1.0

commit be1fb10a523b3b04ad3277aebdd25724cc9c163d
Author: Christine Spang <spang at bestpractical.com>
Date:   Wed Aug 19 18:08:15 2009 +0100

    config/aliases commands don't actually require a handle
    
    They're still useful for setting values in new empty repo by wrapper
    scripts and viewing user-wide config & aliases even without SD_REPO
    pointing at a alreaty-initialised replica.

diff --git a/lib/App/SD/CLI/Dispatcher.pm b/lib/App/SD/CLI/Dispatcher.pm
index d8e132c..4506c02 100644
--- a/lib/App/SD/CLI/Dispatcher.pm
+++ b/lib/App/SD/CLI/Dispatcher.pm
@@ -83,7 +83,7 @@ on qr'.*' => sub {
 on qr'.*' => sub {
     my $self = shift;
     my $command = $_;
-    next_rule if $command =~ /^(?:shell|clone|init)$/;
+    next_rule if $command =~ /^(?:shell|clone|init|config|alias(?:es)?)$/;
     next_rule if $self->cli->app_handle->handle->replica_exists;
 
     print join("\n","No SD database was found at " . $self->cli->app_handle->handle->url(),

commit 602082a0b0f68318067d1b5cab69aeaee40eb7d2
Author: Christine Spang <spang at bestpractical.com>
Date:   Wed Aug 19 18:10:04 2009 +0100

    post-init/clone configuration wizard
    
    For clone and init, if there is no user-wide email address set, check
    $ENV{EMAIL} and see if the user wants to use what's found there.
    Otherwise prompt for an email address to use.
    
    For init only, prompt the user to edit the new db's settings if
    she wants.
    
    Both init and clone will display a message pointing the user at
    some help docs if she has no user-wide config file and thus is
    probably new.

diff --git a/lib/App/SD/CLI/Command/Clone.pm b/lib/App/SD/CLI/Command/Clone.pm
new file mode 100644
index 0000000..41acded
--- /dev/null
+++ b/lib/App/SD/CLI/Command/Clone.pm
@@ -0,0 +1,22 @@
+package App::SD::CLI::Command::Clone;
+use Any::Moose;
+extends 'Prophet::CLI::Command::Clone';
+with 'App::SD::CLI::NewReplicaCommand';
+
+override run => sub {
+    my $self = shift;
+
+    # clone dies if the target replica already exists, so no need
+    # to worry about not running the wizard if the clone doesn't run
+    $self->SUPER::run();
+
+    Prophet::CLI->end_pager();
+
+    $self->new_replica_wizard( edit_settings => 0 );
+};
+
+__PACKAGE__->meta->make_immutable;
+no Any::Moose;
+
+1;
+
diff --git a/lib/App/SD/CLI/Command/Init.pm b/lib/App/SD/CLI/Command/Init.pm
new file mode 100644
index 0000000..f9b407e
--- /dev/null
+++ b/lib/App/SD/CLI/Command/Init.pm
@@ -0,0 +1,20 @@
+package App::SD::CLI::Command::Init;
+use Any::Moose;
+extends 'Prophet::CLI::Command::Init';
+with 'App::SD::CLI::NewReplicaCommand';
+
+override run => sub {
+    my $self = shift;
+
+    my $create_successful = $self->SUPER::run();
+
+    Prophet::CLI->end_pager();
+
+    $self->new_replica_wizard() if $create_successful;
+};
+
+__PACKAGE__->meta->make_immutable;
+no Any::Moose;
+
+1;
+
diff --git a/lib/App/SD/CLI/NewReplicaCommand.pm b/lib/App/SD/CLI/NewReplicaCommand.pm
new file mode 100644
index 0000000..664f97f
--- /dev/null
+++ b/lib/App/SD/CLI/NewReplicaCommand.pm
@@ -0,0 +1,136 @@
+package App::SD::CLI::NewReplicaCommand;
+use Any::Moose 'Role';
+
+# steal email from $ENV{EMAIL} or prompt, and prompt to edit settings
+sub new_replica_wizard {
+    my $self = shift;
+    my %args = (
+        edit_settings => 1,
+        @_,
+    );
+
+    # VCS wrappers themselves should take care of settings email addresses on
+    # init/clone from VCS configuration, don't put that here
+
+    # don't prompt for configuration if there's already a user-wide email set
+    if ( ! defined $self->config->get( key => 'user.email-address' ) ) {
+
+        print "\nYou need an email address configured to use SD. I'll try"
+              ." to find one.\n";
+
+        if ( $ENV{EMAIL} ) {
+            $self->_migrate_email_from_env;
+        }
+    }
+    # if we still don't have an email, ask
+    if ( ! defined $self->config->get( key => 'user.email-address' ) ) {
+        $self->_prompt_email;
+    }
+
+    # new replicas probably want to change settings right away,
+    # at least to change the project name ;)
+    $self->_prompt_edit_settings if $args{edit_settings};
+
+    # this message won't print if the user has a ~/.sdrc, which is
+    # probably a pretty good indication that they're not new
+    my $script = $self->cli->get_script_name;
+    print <<"END_MSG" unless -f $self->config->user_file;
+
+If you're new to SD, you can find out what to do now by looking at
+'${script}help intro' and '${script}help tickets'. You can see a list of all
+help topics with '${script}help'. Have fun!
+END_MSG
+}
+
+# default is the replica-specific config file
+sub _prompt_which_config_file {
+    my $self = shift;
+    my $email = shift;
+
+    print "\nUse '$email' for (a)ll your bug databases, (j)ust"
+            ." this one,\nor (n)ot at all? [a/J/n] ";
+    chomp( my $response = <STDIN> );
+
+    my $config_file = lc $response eq 'a'
+        ? $self->config->user_file
+        : lc $response eq 'n'
+        ? undef
+        : $self->config->replica_config_file;
+
+    return $config_file;
+}
+
+sub _migrate_email_from_env {
+    my $self = shift;
+
+    print "Found '$ENV{EMAIL}' in \$EMAIL.\n";
+    my $config_file = $self->_prompt_which_config_file( $ENV{EMAIL} );
+
+    if ( $config_file ) {
+        $self->config->set(
+            key      => 'user.email-address',
+            value    => $ENV{EMAIL},
+            filename => $config_file,
+        );
+        print "  - added email '$ENV{EMAIL}' to\n    $config_file\n";
+    }
+}
+
+sub _prompt_email {
+    my $self = shift;
+
+    Prophet::CLI->end_pager(); # XXX where does this get turned back on?
+    print "\nCouldn't determine an email address to attribute your SD changes to.\n";
+
+    my $email;
+    while ( ! $email ) {
+        print "What email shall I use? ";
+        chomp( $email = <STDIN> );
+    }
+
+    my $use_dir_config = $self->prompt_choices( 'j', 'a',
+        'Use this for (a)ll your SD databases or (j)ust this one?' );
+
+    my $config_file = $use_dir_config
+                    ? $self->config->replica_config_file
+                    : $self->config->user_file;
+    $self->config->set(
+        key      => 'user.email-address',
+        value    => $email,
+        filename => $config_file,
+    );
+    print "  - added email '$email' to\n    $config_file\n";
+}
+
+sub _prompt_edit_settings {
+    my $self = shift;
+
+    my $prompt_for_settings
+        = $self->prompt_Yn(
+            "\nWant to edit your new bug database's settings now?" );
+    if ( $prompt_for_settings ) {
+        my @classes = App::SD::CLI::Dispatcher->class_names('Settings');
+        for my $class (@classes) {
+            $self->app_handle->try_to_require($class) or next;
+
+            # reset args for new command
+            my $args = {
+                edit => 1,
+            };
+            $self->context->mutate_attributes( args => $args );
+
+            my $command = $class->new(
+                uuid    => $self->context->uuid,
+                cli     => $self->cli,
+                context => $self->context,
+            );
+            $command->run();
+        }
+
+    }
+}
+
+no Any::Moose;
+
+1;
+

-----------------------------------------------------------------------



More information about the Bps-public-commit mailing list