From: Andrew Chilton Date: Tue, 1 Jul 2008 11:44:04 +0000 (+1200) Subject: Added ability to read ~/.cilrc config file (closes #ce8053b0). X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=ed77a7db1ef5d18627d8acec7685047fe5bc68f0;p=cil.git Added ability to read ~/.cilrc config file (closes #ce8053b0). --- diff --git a/bin/cil b/bin/cil index 15d8eac..c29484c 100755 --- 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 and C fields in any +issues/comments/attachments you add. + +=item UserEmail + +Default: 'Email', Type: String + +This is used as a default in the C and C 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 index 0000000..3702f53 --- /dev/null +++ b/issues/c_4d6c02bb.cil @@ -0,0 +1,12 @@ +Issue: ce8053b0 +CreatedBy: Andrew Chilton +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. diff --git a/issues/i_ce8053b0.cil b/issues/i_ce8053b0.cil index dcbb873..7669a1e 100644 --- a/issues/i_ce8053b0.cil +++ b/issues/i_ce8053b0.cil @@ -1,11 +1,12 @@ Summary: Ability to have a ~/.cilrc file -Status: New +Status: Finished CreatedBy: Andrew Chilton AssignedTo: Andrew Chilton 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: diff --git a/lib/CIL.pm b/lib/CIL.pm index f64d67a..c0a55c6 100644 --- a/lib/CIL.pm +++ b/lib/CIL.pm @@ -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