]> git.mjollnir.org Git - cil.git/commitdiff
Added ability to read ~/.cilrc config file (closes #ce8053b0).
authorAndrew Chilton <andychilton@gmail.com>
Tue, 1 Jul 2008 11:44:04 +0000 (23:44 +1200)
committerAndrew Chilton <andychilton@gmail.com>
Tue, 1 Jul 2008 11:44:04 +0000 (23:44 +1200)
bin/cil
issues/c_4d6c02bb.cil [new file with mode: 0644]
issues/i_ce8053b0.cil
lib/CIL.pm

diff --git a/bin/cil b/bin/cil
index 15d8eac5ddde9055d3bfb8396eba9a79eb050183..c29484c1587ee3c4db8a1093a4be6c632320789a 100755 (executable)
--- a/bin/cil
+++ b/bin/cil
@@ -70,9 +70,6 @@ my %BOOLEAN_ARGS = (
     'is-closed' => 1,
 );
 
-my $gan = $ENV{GIT_AUTHOR_NAME} || 'Your Name';
-my $gae = $ENV{GIT_AUTHOR_EMAIL} || 'you@example.org';
-
 ## ----------------------------------------------------------------------------
 # main program
 
@@ -101,7 +98,8 @@ my $gae = $ENV{GIT_AUTHOR_EMAIL} || 'you@example.org';
     }
 
     my $cil = CIL->new();
-    $cil->read_config_file( '.cil' );
+    $cil->read_config_user();
+    $cil->read_config_file();
 
     &{"cmd_$command"}($cil, $args, @ARGV);
 }
@@ -225,10 +223,12 @@ sub cmd_add {
 
     CIL::Utils->ensure_interactive();
 
+    my $user = user($cil);
+
     my $issue = CIL::Issue->new('tmpname');
     $issue->Status('New');
-    $issue->CreatedBy("$gan <$gae>");
-    $issue->AssignedTo("$gan <$gae>");
+    $issue->CreatedBy( $user );
+    $issue->AssignedTo( $user );
     $issue->Description("Description ...");
 
     add_issue_loop($cil, undef, $issue);
@@ -277,7 +277,7 @@ sub cmd_comment {
     # create the new comment
     my $comment = CIL::Comment->new('tmpname');
     $comment->Issue( $issue->name );
-    $comment->CreatedBy("$gan <$gae>");
+    $comment->CreatedBy( user($cil) );
     $comment->Description("Description ...");
 
     add_comment_loop($cil, undef, $issue, $comment);
@@ -294,10 +294,11 @@ sub cmd_attach {
     }
 
     my $basename = basename( $filename );
+    my $user = user($cil);
 
     my $add_attachment_text = <<"EOF";
 Filename    : $basename
-CreatedBy   : $gan <$gae>
+CreatedBy   : $user
 
 File goes here ... this will be overwritten.
 EOF
@@ -532,7 +533,7 @@ sub cmd_am {
         $issue->Summary( $subject );
         $issue->Status( 'New' );
         $issue->CreatedBy( $from );
-        $issue->AssignedTo( "$gan <$gae>" );
+        $issue->AssignedTo( user($cil) );
         $issue->Inserted( $date );
         $issue->Updated( $date );
         $issue->Description( $body );
@@ -862,6 +863,11 @@ sub display_attachment {
     field( 'Updated', $attachment->Inserted() );
 }
 
+sub user {
+    my ($cil) = @_;
+    return $cil->UserName . ' <' . $cil->UserEmail . '>';
+}
+
 ## ----------------------------------------------------------------------------
 # helper functions for this command line tool
 
@@ -1125,6 +1131,33 @@ This determines which labels are allowed if you have turned on LabelStrict.
 
 =back
 
+=head1 ~/.cilrc
+
+The C<~/.cilrc> file is read to configure the user's preferences for all cil
+lists they're using. It is of the same format as the C<.cil> file and contains
+the following options:
+
+    UserName: Andrew Chilton
+    UserEmail: andychilton@gmail.com
+
+=over
+
+=item UserName
+
+Default: 'Name', Type: String
+
+This is used as a default in the C<CreatedBy> and C<AssignedTo> fields in any
+issues/comments/attachments you add.
+
+=item UserEmail
+
+Default: 'Email', Type: String
+
+This is used as a default in the C<CreatedBy> and C<AssignedTo> fields in any
+issues/comments/attachments you add.
+
+=back
+
 =head1 BUGS
 
 Probably. Let me know :-)
diff --git a/issues/c_4d6c02bb.cil b/issues/c_4d6c02bb.cil
new file mode 100644 (file)
index 0000000..3702f53
--- /dev/null
@@ -0,0 +1,12 @@
+Issue: ce8053b0
+CreatedBy: Andrew Chilton <andychilton@gmail.com>
+Inserted: 2008-07-01T11:33:55
+Updated: 2008-07-01T11:34:38
+
+Added the ability to read the ~/.cilrc config file. The only things it can
+contain for now are:
+
+* UserName
+* UserEmail
+
+but we can easily add more as time goes on.
index dcbb87373697eccaf768b8b222f48a50599967c0..7669a1e78a7367cfc06633ab3a3397d3262478bc 100644 (file)
@@ -1,11 +1,12 @@
 Summary: Ability to have a ~/.cilrc file
-Status: New
+Status: Finished
 CreatedBy: Andrew Chilton <andychilton@gmail.com>
 AssignedTo: Andrew Chilton <andychilton@gmail.com>
 Label: Milestone-v0.4
 Label: Type-Enhancement
+Comment: 4d6c02bb
 Inserted: 2008-06-28T23:44:50
-Updated: 2008-06-29T10:13:57
+Updated: 2008-07-01T11:34:38
 
 The ability to have a ~/.cilrc file can help with the following:
 
index f64d67a0bc5a18ed68d6879c1b26bc00428eff52..c0a55c6896ef72d1ffe09c4124dc42c10142294e 100644 (file)
@@ -30,6 +30,7 @@ __PACKAGE__->mk_accessors(qw(
     IssueDir
     StatusStrict StatusAllowed StatusOpen StatusClosed
     LabelStrict LabelAllowed
+    UserName UserEmail
 ));
 
 my $defaults = {
@@ -40,6 +41,11 @@ my $defaults = {
 
 my @config_hashes = qw(StatusAllowed StatusOpen StatusClosed LabelAllowed);
 
+my $defaults_user = {
+    UserName  => 'Name',
+    UserEmail => 'me@example.com',
+};
+
 ## ----------------------------------------------------------------------------
 
 sub new {
@@ -179,8 +185,26 @@ sub get_attachments_for {
     return \@attachments;
 }
 
+sub read_config_user {
+    my ($self) = @_;
+
+    my $filename = "$ENV{HOME}/.cilrc";
+
+    my $cfg;
+    if ( -f $filename ) {
+        $cfg = CIL::Utils->parse_cil_file( $filename );
+    }
+
+    # set each config to be either the user defined one or the default
+    foreach ( qw(UserName UserEmail) ) {
+        $self->$_( $cfg->{$_} || $defaults_user->{$_} );
+    }
+}
+
 sub read_config_file {
-    my ( $self, $filename ) = @_;
+    my ( $self ) = @_;
+
+    my $filename = '.cil';
 
     # since we might not have a '.cil' file yet (in the case where we're calling 'init',
     # then we should just return whatever the defaults are