From: Andrew Chilton Date: Mon, 23 Jun 2008 12:14:00 +0000 (+1200) Subject: Add ability to filter on both the Status and Label fields. X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=6f5cf425e678cd8e50bad8ab9ee0c568bb947fd8;p=cil.git Add ability to filter on both the Status and Label fields. --- diff --git a/bin/cil b/bin/cil index 9a829fd..59b40f8 100755 --- a/bin/cil +++ b/bin/cil @@ -20,8 +20,6 @@ use strict; use warnings; -use Data::Dumper; - use Getopt::Mixed "nextOption"; use Digest::MD5 qw(md5_hex); use File::Touch; @@ -43,6 +41,10 @@ my @IN_OPTS = ( 'path>p', # for 'add' 'f=s', # f = filename 'filename>f', # for 'extract' + 's=s', # s = status + 'status>s', # for 'summary', 'list' + 'l=s', # l = label + 'label>l', # for 'summary, 'list' 'help', 'version', @@ -154,12 +156,13 @@ README } sub cmd_list { - my ($cil) = @_; + my ($cil, $args) = @_; check_paths($cil); # find all the issues my $issues = $cil->get_issues(); + $issues = filter_issues( $issues, $args ); if ( @$issues ) { foreach my $issue ( sort { $a->Inserted cmp $b->Inserted } @$issues ) { separator(); @@ -173,12 +176,13 @@ sub cmd_list { } sub cmd_summary { - my ($cil) = @_; + my ($cil, $args) = @_; check_paths($cil); # find all the issues my $issues = $cil->get_issues(); + $issues = filter_issues( $issues, $args ); if ( @$issues ) { separator(); foreach my $issue ( @$issues ) { @@ -369,6 +373,32 @@ sub check_paths { } } +sub filter_issues { + my ($issues, $args) = @_; + + return unless %$args; + + # take a copy of the whole lot first (so we don't destroy the input list) + my @new_issues = @$issues; + + # firstly, get out the Statuses we want + if ( defined $args->{s} ) { + @new_issues = grep { $_->Status eq $args->{s} } @new_issues; + } + + # then see if we want a particular label (could be a bit nicer) + if ( defined $args->{l} ) { + my @tmp; + foreach my $issue ( @new_issues ) { + push @tmp, $issue + if grep { $_ eq $args->{l} } @{$issue->Labels}; + } + @new_issues = @tmp; + } + + return \@new_issues; +} + ## ---------------------------------------------------------------------------- # input/output @@ -535,8 +565,8 @@ Usage: $0 COMMAND [options] Commands: init [--path=PATH] add - summary - list + summary [--status=STATUS] [--label=LABEL] + list [--status=STATUS] [--label=LABEL] show ISSUE status ISSUE NEW_STATUS edit ISSUE @@ -560,6 +590,8 @@ cil - the command-line issue list $ cil init $ cil summary $ cil list + $ cil list --status=New + $ cil list --label=Release-v0.1 $ cil add ... added issue 'cafebabe' ... @@ -588,13 +620,15 @@ and attachments as local files which you can check in to your repository. Creates a local '.cil' file and an 'issues' directory. If PATH is specified, the config file and directory will be created in the destination directory. -=item summary +=item summary [--status=STATUS] [--label=LABEL] -Displays a one line summary for each issue. +Displays a one line summary for each issue. You may filter on both the Status +and Label fields. -=item list +=item list [--status=STATUS] [--label=LABEL] -Shows each issue with more information. +Shows each issue with more information. You may filter on both the Status and +Label fields. =item add diff --git a/issues/c_7eb313cd.cil b/issues/c_7eb313cd.cil new file mode 100644 index 0000000..8d97144 --- /dev/null +++ b/issues/c_7eb313cd.cil @@ -0,0 +1,11 @@ +Issue: 85eceee9 +CreatedBy: Andrew Chilton +Inserted: 2008-06-23T12:07:44 +Updated: 2008-06-23T12:07:44 + +Added both --status and --label. + +In the case of Status, it tests for equality. + +In the case of Label, it tests that the issue has at least one label of the one +specified. diff --git a/issues/i_85eceee9.cil b/issues/i_85eceee9.cil index 9f99323..22b7212 100644 --- a/issues/i_85eceee9.cil +++ b/issues/i_85eceee9.cil @@ -1,12 +1,13 @@ Summary: Ability to filter the issues lists (summary and list) -Status: New +Status: InProgress CreatedBy: Andrew Chilton AssignedTo: Andrew Chilton Label: Milestone-v0.3 Label: Release-v0.2 Label: Type-Enhancement +Comment: 7eb313cd Inserted: 2008-06-23T12:05:33 -Updated: 2008-06-23T12:05:33 +Updated: 2008-06-23T12:08:05 The ability to filter on various things would be nice. For example using these list commands, though summary should work the same way: diff --git a/lib/CIL/Issue.pm b/lib/CIL/Issue.pm index 0dfaf53..13f3435 100644 --- a/lib/CIL/Issue.pm +++ b/lib/CIL/Issue.pm @@ -129,6 +129,11 @@ sub as_output { return CIL::Utils->format_data_as_output( $self->{data}, @FIELDS ); } +sub Labels { + my ($self) = @_; + return $self->{data}{Label}; +} + sub Comments { my ($self) = @_; return $self->{data}{Comment};