]> mj.ucw.cz Git - bex.git/commitdiff
add: Added --execute switch
authorMartin Mares <mj@ucw.cz>
Thu, 16 Feb 2012 16:42:33 +0000 (17:42 +0100)
committerMartin Mares <mj@ucw.cz>
Thu, 16 Feb 2012 16:42:33 +0000 (17:42 +0100)
lib/bin/bex-add

index 6cfbd17a25f2871dccb4ec9ca2f38629bec03755..56f58fabfaad70a8c389eb0a5d665c315f89c74d 100755 (executable)
@@ -9,6 +9,7 @@ use File::stat;
 use BEX;
 
 my $given_body;
+my $given_execute;
 my $given_go;
 my $given_id;
 my $queue_name;
@@ -22,6 +23,7 @@ Usage: bex add [<options>] [!]<machine-or-class> ...
 
 Options:
 -b, --body=<file>      Load job body from the given file
+-e, --execute=<command>        Set job body to the given command
 -g, --go               Do not run editor, go enqueue the job immediately
 -i, --id=<id>          Set job ID of the new job
 -q, --queue=<name>     Insert new jobs to the given queue
@@ -34,6 +36,7 @@ AMEN
 
 GetOptions(
        "b|body=s" => \$given_body,
+       "e|execute=s" => \$given_execute,
        "g|go!" => \$given_go,
        "i|id=s" => \$given_id,
        "q|queue=s" => \$queue_name,
@@ -54,7 +57,7 @@ my $tmp_fn;
 
 if (defined $requeue_id) {
        # When requeueing, just fetch the existing job
-       if (defined($given_body) || defined($given_id) || defined($given_subject) || defined($given_template)) {
+       if (defined($given_body) || defined($given_execute) || defined($given_id) || defined($given_subject) || defined($given_template)) {
                die "Parameters of a requeued job cannot be changed\n";
        }
        my $fn = $queue->job_file($requeue_id);
@@ -69,7 +72,9 @@ if (defined $requeue_id) {
        }
        $job->attr('ID', $given_id) if defined $given_id;
        $job->attr('Subject', $given_subject) if defined $given_subject;
-       if (defined $given_body) {
+       if (defined $given_execute) {
+               $job->attr('body', $given_execute. "\n");
+       } elsif (defined $given_body) {
                open B, '<', $given_body or die "Cannot open $given_body: $!\n";
                local $/;
                $job->attr('body', <B>);