]> git.mjollnir.org Git - cil.git/commitdiff
Issue:6 - Allow ability to --order on various fields (also --reverse has been added...
authorAndrew Chilton <andychilton@gmail.com>
Sun, 31 Jul 2011 02:59:22 +0000 (14:59 +1200)
committerAndrew Chilton <andychilton@gmail.com>
Sun, 31 Jul 2011 02:59:22 +0000 (14:59 +1200)
bin/cil
lib/CIL/Command/List.pm
lib/CIL/Command/Summary.pm
lib/CIL/Utils.pm

diff --git a/bin/cil b/bin/cil
index 5c210d86300c0f3c741549dcf27279a56ff7725b..2d5afe65b3b4391fac2202dbe006d4d5c69ab7a5 100755 (executable)
--- a/bin/cil
+++ b/bin/cil
@@ -51,14 +51,17 @@ my @IN_OPTS = (
     'created-by>c', # for 'summary', 'list'
     'a=s',          # a = assigned_to
     'assigned-to>a',# for 'summary', 'list'
+    'o=s',          # o = order
+    'order>o',      # for 'summary', 'list'
     'r=s',          # r = revision
-    'revision>s',   # for all query commands
+    'revision>r',   # for all query commands
 
     # booleans
     'bare',         # for 'init'
     'is-open',      # for 'summary', 'list'
     'is-closed',    # for 'summary', 'list'
     'is-mine',      # for 'summary', 'list'
+    'reverse',      # for 'summary', 'list'
     'mine',         # for 'add'
     'add',          # for 'add', 'comment'
     'commit',       # for 'add', 'comment'
@@ -75,6 +78,7 @@ my %BOOLEAN_ARGS = (
     'is-open'   => 1,
     'is-closed' => 1,
     'is-mine'   => 1,
+    'reverse'   => 1,
     'mine'      => 1,
     'add'       => 1,
     'commit'    => 1,
@@ -177,7 +181,9 @@ cil - the command-line issue list
     $ cil list
     $ cil list --status=New
     $ cil list --label=Release-v0.1
-    $ cil list --is-open
+    $ cil list --is-open --order=Updated
+    $ cil list --order=Updated --reverse
+    $ cil list --order=Inserted
 
     $ cil add
     ... added issue 'cafebabe' ...
@@ -341,6 +347,34 @@ C<UserEmail>.
 
 =back
 
+=head1 ORDER
+
+When doing a 'summary' or a 'list', as well as filtering the issues to only
+show what you want, you can also order them to show them in whichever order you
+like too. The fields you can order by are:
+
+    --order=Summary
+    --order=Inserted
+    --order=Updated
+    --order=AssignedTo
+    --order=CreatedBy
+    --order=DueDate
+    --order=Status
+
+In the case of Summary, Inserted, Updated, CreatedBy and Status the field is
+always defined and hence the ordering will take every issue into
+account. However, some issues may not have been assigned or have a due date, so
+AssignedTo and DueDate may be blank. In this case, any issues with these fields
+defined are ordered and any issues which do not have this field are placed
+towards the bottom of the listing.
+
+=head2 REVERSE
+
+Every single one of these orderings can also be reversed using the C<--reverse>
+flag. If an ordering is reversed it works as expected but again for issues
+where that field is undefined they are placed at the bottom (rather than having
+the undefined values float to the top).
+
 =head1 .cil
 
 The C<.cil> file is used to configure bits and pieces within cil for this
@@ -455,7 +489,7 @@ Andrew Chilton <andychilton@gmail.com>
 
 =head1 COPYRIGHT
 
-Copyright (C) 2008 by Andrew Chilton
+Copyright (C) 2008-2011 by Andrew Chilton
 
 Cil is free software: you can redistribute it and/or modify it under the terms
 of the GNU General Public License as published by the Free Software Foundation,
index 98fbad4eeb3d0856058ed3d1dde5e6748bd68e2f..6b67ff97c389710838797203f8fd4993227812ec 100644 (file)
@@ -37,7 +37,8 @@ sub run {
     my $issues = $cil->get_issues();
     $issues = CIL::Utils->filter_issues( $cil, $issues, $args );
     if ( @$issues ) {
-        foreach my $issue ( sort { $a->Inserted cmp $b->Inserted } @$issues ) {
+        $issues = CIL::Utils->order_issues( $cil, $issues, $args );
+        foreach my $issue ( @$issues ) {
             CIL::Utils->separator();
             CIL::Utils->display_issue_headers($issue);
         }
index 2a5e3257a1f3e998f6c34115878be7d166fab0fa..c22b8eae963407a742eaf577dba38d5c985ce6da 100644 (file)
@@ -38,6 +38,7 @@ sub run {
     $issues = CIL::Utils->filter_issues( $cil, $issues, $args );
     if ( @$issues ) {
         CIL::Utils->separator();
+        $issues = CIL::Utils->order_issues( $cil, $issues, $args );
         foreach my $issue ( @$issues ) {
             CIL::Utils->display_issue_summary($issue);
         }
index 6ca3cf47a7cebc1665cfd4884e749b95f6c51bb8..a76f513d38f2e40853d7823a08734e6c3bafd042 100644 (file)
@@ -473,6 +473,48 @@ sub filter_issues {
     return \@new_issues;
 }
 
+my $valid_order = {
+    Summary    => 1,
+    Inserted   => 1,
+    Updated    => 1,
+    AssignedTo => 1,
+    CreatedBy  => 1,
+    DueDate    => 1,
+    Status     => 1,
+};
+
+sub order_issues {
+    my ($class, $cil, $issues, $args) = @_;
+
+    # don't order if we haven't been given anything
+    return $issues unless defined $args;
+    return $issues unless %$args;
+    return $issues unless defined $args->{o};
+
+    my $order_by = $args->{o};
+
+    # make sure that the order is allowed
+    unless ( exists $valid_order->{$order_by} ) {
+        $class->fatal("the --order must be one of: " . join(', ', sort keys %$valid_order));
+    }
+
+    # Split off the ones with this field defined/not defined.
+    my @defined   = grep {   $_->{data}{$order_by} } @$issues;
+    my @undefined = grep { ! $_->{data}{$order_by} } @$issues;
+
+    @$issues = sort { $a->{data}{$order_by} cmp $b->{data}{$order_by} } @defined;
+
+    # reverse the order if specified
+    if ( $args->{reverse} ) {
+        @$issues = reverse @$issues;
+    }
+
+    # now put the undefined ones back (so they're at the bottom independent of --order and --reverse)
+    push @$issues, @undefined;
+
+    return $issues;
+}
+
 sub separator {
     my ($class) = @_;
     $class->msg('=' x 79);