'is-closed' => 1,
);
-my $gan = $ENV{GIT_AUTHOR_NAME} || 'Your Name';
-my $gae = $ENV{GIT_AUTHOR_EMAIL} || 'you@example.org';
-
## ----------------------------------------------------------------------------
# main program
}
my $cil = CIL->new();
- $cil->read_config_file( '.cil' );
+ $cil->read_config_user();
+ $cil->read_config_file();
&{"cmd_$command"}($cil, $args, @ARGV);
}
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);
# 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);
}
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
$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 );
field( 'Updated', $attachment->Inserted() );
}
+sub user {
+ my ($cil) = @_;
+ return $cil->UserName . ' <' . $cil->UserEmail . '>';
+}
+
## ----------------------------------------------------------------------------
# helper functions for this command line tool
=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 :-)
IssueDir
StatusStrict StatusAllowed StatusOpen StatusClosed
LabelStrict LabelAllowed
+ UserName UserEmail
));
my $defaults = {
my @config_hashes = qw(StatusAllowed StatusOpen StatusClosed LabelAllowed);
+my $defaults_user = {
+ UserName => 'Name',
+ UserEmail => 'me@example.com',
+};
+
## ----------------------------------------------------------------------------
sub new {
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