From 28fa77ec635c1eb10563565555e381bb573e73b4 Mon Sep 17 00:00:00 2001 From: Andrew Chilton Date: Sat, 23 Jan 2010 19:39:01 +1300 Subject: [PATCH] cil-5ec585b1: Now you can remove labels if you specify --remove to 'cil label' --- bin/cil | 2 ++ issues/c_043f8971.cil | 6 ++++++ issues/i_5ec585b1.cil | 7 ++++--- lib/CIL/Command/Label.pm | 13 ++++++++++--- lib/CIL/Issue.pm | 11 +++++++++++ 5 files changed, 33 insertions(+), 6 deletions(-) create mode 100644 issues/c_043f8971.cil diff --git a/bin/cil b/bin/cil index 6b579af..5a206ce 100755 --- a/bin/cil +++ b/bin/cil @@ -63,6 +63,7 @@ my @IN_OPTS = ( 'add', # for 'add', 'comment' 'commit', # for 'add', 'comment' 'batch', # for 'am' + 'remove', # for 'label' 'help', 'version', ); @@ -78,6 +79,7 @@ my %BOOLEAN_ARGS = ( 'add' => 1, 'commit' => 1, 'batch' => 1, + 'remove' => 1, ); ## ---------------------------------------------------------------------------- diff --git a/issues/c_043f8971.cil b/issues/c_043f8971.cil new file mode 100644 index 0000000..d317428 --- /dev/null +++ b/issues/c_043f8971.cil @@ -0,0 +1,6 @@ +Issue: 5ec585b1 +CreatedBy: Andrew Chilton +Inserted: 2010-01-23T06:37:08 +Updated: 2010-01-23T06:37:20 + +Now done. Should remove the correct label specified. diff --git a/issues/i_5ec585b1.cil b/issues/i_5ec585b1.cil index c68fa96..caab419 100644 --- a/issues/i_5ec585b1.cil +++ b/issues/i_5ec585b1.cil @@ -1,12 +1,13 @@ Summary: Add a cil label --remove command -Status: New +Status: Finished CreatedBy: Andrew Chilton AssignedTo: Andrew Chilton Label: Milestone-v0.06 +Comment: 043f8971 Inserted: 2010-01-22T01:41:59 -Updated: 2010-01-22T01:43:31 +Updated: 2010-01-23T06:37:44 Currently you can 'cil label MyLabel cafebabe' but you can't remove it. Add the following option: - $ cil label --remote MyLabel cafebabe + $ cil label --remove MyLabel cafebabe diff --git a/lib/CIL/Command/Label.pm b/lib/CIL/Command/Label.pm index 58f0e1c..534a182 100644 --- a/lib/CIL/Command/Label.pm +++ b/lib/CIL/Command/Label.pm @@ -37,13 +37,20 @@ sub run { CIL::Utils->fatal("provide a valid label to add to this issue"); } - # for every issue, read it it and add the label + # for every issue foreach my $issue_name ( @issue_names ) { # firstly, read the issue in my $issue = CIL::Utils->load_issue_fuzzy( $cil, $issue_name ); - # set the status for this issue - $issue->add_label( $label ); + # decide whether we are adding or removing this label + if ( $args->{remove} ) { + $issue->remove_label( $label ); + } + else { + $issue->add_label( $label ); + } + + # save $issue->save($cil); # if we want to add or commit this issue diff --git a/lib/CIL/Issue.pm b/lib/CIL/Issue.pm index 77badac..75ca7b7 100644 --- a/lib/CIL/Issue.pm +++ b/lib/CIL/Issue.pm @@ -138,6 +138,17 @@ sub add_label { $self->flag_as_updated(); } +sub remove_label { + my ($self, $label) = @_; + + croak 'provide a label when removing one' + unless defined $label; + + # remove this label + @{$self->{data}{Label}} = grep { $_ ne $label } @{$self->{data}{Label}}; + $self->flag_as_updated(); +} + sub add_comment { my ($self, $comment) = @_; -- 2.39.5