]> git.mjollnir.org Git - cil.git/commitdiff
Add ability to filter on both the Status and Label fields.
authorAndrew Chilton <andychilton@gmail.com>
Mon, 23 Jun 2008 12:14:00 +0000 (00:14 +1200)
committerAndrew Chilton <andychilton@gmail.com>
Mon, 23 Jun 2008 12:14:00 +0000 (00:14 +1200)
bin/cil
issues/c_7eb313cd.cil [new file with mode: 0644]
issues/i_85eceee9.cil
lib/CIL/Issue.pm

diff --git a/bin/cil b/bin/cil
index 9a829fd34f9580fafbe7ede1bdfca67f098815c3..59b40f899bcf2429536569f9674a484d9aa2f051 100755 (executable)
--- 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 (file)
index 0000000..8d97144
--- /dev/null
@@ -0,0 +1,11 @@
+Issue: 85eceee9
+CreatedBy: Andrew Chilton <andychilton@gmail.com>
+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.
index 9f993235922772a654ccac52f3c569ce4168b463..22b72126d79db9f2b7a40904392fca7d9b2aff6a 100644 (file)
@@ -1,12 +1,13 @@
 Summary: Ability to filter the issues lists (summary and list)
-Status: New
+Status: InProgress
 CreatedBy: Andrew Chilton <andychilton@gmail.com>
 AssignedTo: Andrew Chilton <andychilton@gmail.com>
 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:
index 0dfaf533768dceaea6be54ccb0a96cb1dcd5aa7b..13f34355719671e6a176988c8c93c09f5d1ef0cb 100644 (file)
@@ -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};