use CIL::Issue;
use Term::CallEditor;
use File::Touch;
-use YAML;
use File::Glob ':glob';
use File::Basename;
list => 1,
add => 1,
show => 1,
+ edit => 1,
};
my $new_issue_text = <<"EOF";
my ($command) = shift;
unless ( defined $command and exists $COMMANDS->{$command} ) {
usage();
- exit 1;
+ exit 2;
}
if ( $command eq 'init' ) {
elsif ( $command eq 'add' ) {
add();
}
+ elsif ( $command eq 'edit' ) {
+ my ($issue_name) = @ARGV;
+ edit($issue_name);
+ }
+
+ else {
+ fatal("program error when trying command '$command'");
+ }
}
# firstly, read the issue in
my $issue = CIL::Issue->new_load_issue($issue_name);
unless ( defined $issue ) {
- print STDERR "Couldn't load issue '$issue'\n";
- return;
+ fatal("Couldn't load issue '$issue'");
}
display_issue_full( $issue );
}
display_issue_full( $issue );
}
+sub edit {
+ my ($issue_name) = @_;
+
+ my $issue = CIL::Issue->new_load_issue($issue_name);
+ unless ( defined $issue ) {
+ fatal("Couldn't load issue '$issue'");
+ }
+
+ my $summary = $issue->Summary;
+ my $status = $issue->Status;
+ my $created_by = $issue->CreatedBy;
+ my $labels = $issue->Labels;
+ my $description = $issue->Description;
+
+ # create the ini file, then edit it
+ my $edit_issue_text = <<"EOF";
+[Issue]
+
+Summary = $summary
+Status = $status
+CreatedBy = $created_by
+Labels = $labels
+Description = <<END_OF_DESCRIPTION
+$description
+END_OF_DESCRIPTION
+EOF
+
+ # read in the new issue text
+ my $fh = solicit( $edit_issue_text );
+
+ my $issue_edited;
+ eval {
+ $issue_edited = CIL::Issue->new_parse_issue( $fh );
+ };
+ if ( $@ ) {
+ fatal("couldn't parse issue: $@");
+ }
+ unless ( defined $issue_edited ) {
+ fatal("couldn't parse issue (program error)");
+ }
+
+ # for the fields we're interested in, set them
+ foreach my $field ( qw(Summary Status CreatedBy Labels Description) ) {
+ $issue->$field( $issue_edited->$field() );
+ }
+ if ( $issue->changed ) {
+ $issue->save();
+ }
+ else {
+ msg('Issue not changed');
+ }
+}
+
## ----------------------------------------------------------------------------
sub check_paths {
msg "";
}
+sub err {
+ print STDERR ( defined $_[0] ? $_[0] : '' );
+ print STDERR "\n";
+}
+
sub fatal {
my ($msg) = @_;
chomp $msg;
add
list
show <issue>
+ edit <issue>
See <http://kapiti.geek.nz/software/cil.html> for further information.
Report bugs to <andychilton -at- gmail -dot- com>.
use base qw(CIL::Base);
__PACKAGE__->mk_accessors(qw(Name Summary Status Labels Comments));
-my @ATTRS = ( qw(Name Summary Description CreatedBy Status Labels Comments) );
+my @FIELDS = ( qw(Name Summary Description CreatedBy Status Labels Comments) );
## ----------------------------------------------------------------------------
my ($proto) = @_;
my $class = ref $proto || $proto;
my $self = {};
+ $self->{data} = {};
+ $self->{Changed} = 0;
bless $self, $class;
$self->inserted;
return $self;
}
# my $issue = CIL::Issue->new();
- foreach my $attr ( qw(Summary Name Description CreatedBy Status Labels Inserted Updated) ) {
+ foreach my $field ( qw(Summary Name Description CreatedBy Status Labels Inserted Updated) ) {
# modify the data directly, otherwise Updated will kick in
- $issue->{data}{$attr} = $cfg->val( 'Issue', $attr );
+ $issue->{data}{$field} = $cfg->val( 'Issue', $field );
}
$issue->{data}{Comments} = [];
}
my $issue = CIL::Issue->new();
- foreach my $attr ( qw(Summary Name Description CreatedBy Status Labels Inserted Updated) ) {
+ foreach my $field ( qw(Summary Name Description CreatedBy Status Labels Inserted Updated) ) {
# modify the data directly, otherwise Updated will kick in
- $issue->set_no_update($attr, $cfg->val( 'Issue', $attr ));
+ my $value = $cfg->val( 'Issue', $field );
+ next unless defined $value;
+
+ $value =~ s/^\s*//;
+ $value =~ s/\s*$//;
+ $issue->set_no_update($field, $value);
}
$issue->set_no_update('Comments', []);
return $issue;
sub reset {
my ($self) = @_;
- foreach my $attr ( @ATTRS ) {
- delete $self->{$attr};
+ foreach my $field ( @FIELDS ) {
+ delete $self->{$field};
}
}