[Bps-public-commit] r9740 - in Net-Hiveminder: bin

sartak at bestpractical.com sartak at bestpractical.com
Fri Nov 23 19:08:27 EST 2007


Author: sartak
Date: Fri Nov 23 19:08:27 2007
New Revision: 9740

Modified:
   Net-Hiveminder/   (props changed)
   Net-Hiveminder/bin/hm

Log:
 r45556 at onn:  sartak | 2007-11-23 19:08:05 -0500
 More commands, some refactors


Modified: Net-Hiveminder/bin/hm
==============================================================================
--- Net-Hiveminder/bin/hm	(original)
+++ Net-Hiveminder/bin/hm	Fri Nov 23 19:08:27 2007
@@ -4,54 +4,67 @@
 use Net::Hiveminder;
 use Getopt::Long;
 use Pod::Usage;
+use File::Temp;
 
 our $CONFFILE = "$ENV{HOME}/.hiveminder";
 our $VERSION = 0.01;
 our %args;
+our @args;
 our $hm;
 our %config;
 
+our %unaccepted_query = (
+    complete_not => 1,
+    unaccepted   => 1,
+);
+
+our %requests_query = (
+    requestor    => "me",
+    owner_not    => "me",
+    complete_not => 1,
+);
+
 terminal();
 get_options();
 main();
 
 sub main {
-    # log in
-    $hm = Net::Hiveminder->new(use_config => 1, config_file => $CONFFILE);
-    %config = %{ $hm->config };
-
-    canonicalize_options();
-
     my %commands = (
-        list      => \&list_tasks,
-        ls        => \&list_tasks,
-        todo      => \&list_tasks,
+        list       => \&list_tasks,
+        ls         => \&list_tasks,
+        todo       => \&list_tasks,
+        unaccepted => sub {list_tasks(%unaccepted_query)},
+        requests   => sub {list_tasks(%requests_query)},
+
+        add        => sub {$hm->create_task("@ARGV")},
+        bd         => \&braindump,
+        braindump  => \&braindump,
 
-#        add       => \&add_task,
 #        do        => \&do_task,
 #        done      => \&do_task,
 #        del       => \&del_task,
 #        rm        => \&del_task,
 #        edit      => \&edit_task,
 #        tag       => \&tag_task,
-#        unaccepted   => sub {list_tasks($unaccepted_query)},
 #        accept    => \&accept_task,
 #        decline   => \&decline_task,
 #        assign    => \&assign_task,
-#        requests  => sub {list_tasks($requests_query)},
 #        hide      => \&hide_task,
 #        comment   => \&comment_task,
 #        dl        => \&download_textfile,
 #        download  => \&download_textfile,
 #        ul        => \&upload_textfile,
 #        upload    => \&upload_textfile,
-#        bd        => \&braindump,
-#        braindump => \&braindump,
        );
 
     my $command = shift @ARGV || "list";
     $commands{$command} or pod2usage(-message => "Unknown command: $command", -exitval => 2);
 
+    # log in
+    $hm = Net::Hiveminder->new(use_config => 1, config_file => $CONFFILE);
+    %config = %{ $hm->config };
+    canonicalize_options();
+
     $commands{$command}->();
 }
 
@@ -70,7 +83,6 @@
                "priority|pri=s",
                "due=s",
                "hide=s",
-               "owner=s",
                "help",
                "version",
                "config=s",
@@ -86,13 +98,39 @@
 }
 
 sub canonicalize_options {
-    push @{$args{tag}}, split /\s+/, $args{tags} if $args{tags};
+    $args{priority} &&= $hm->canonicalize_priority($args{priority});
 
-    $args{priority} = $hm->canonicalize_priority($args{priority});
-    $args{owner} ||= "me";
+    # the ; is here so Perl interprets it as a codeblock and not a hashref
+    @args = map { ; tag => $_ } split ' ', $args{tags};
+
+    for (qw/group priority due hide/) {
+        push @args, $_ => $args{$_}
+            if $args{$_};
+    }
+
+    return @args;
 }
 
 sub list_tasks {
-    print $hm->todo . "\n";
+    # if there are any qualifiers, use the generic search instead of todo
+    my $method = @_ ? 'get_tasks' : 'todo_tasks';
+
+    push @_, @args;
+    print $hm->display_tasks( $hm->$method(@_) ) . "\n";
+}
+
+sub braindump {
+    my $editor = $ENV{EDITOR}
+        or pod2usage(-message => "Need to specify \$EDITOR.",
+                     -exitval => 1);
+
+    my $fh = File::Temp->new(UNLINK => 0);
+    my $fn = $fh->filename;
+    $fh->close;
+
+    # Call the editor with the file as the first arg
+    system($editor, $fn);
+    $hm->upload_file($fn);
+    unlink $fn;
 }
 



More information about the Bps-public-commit mailing list