Add 'whenjobs --tail <serial>' to tail output messages from jobs.
[whenjobs.git] / tools / whenjobs.ml
index c792e26..be38f67 100644 (file)
@@ -95,6 +95,7 @@ let rec main () =
     "--lib", Arg.Set_string libdir, "dir Specify directory that contains pa_when.cmo";
     "--set", Arg.Unit (set_mode `Set), " Set the variable";
     "--start", Arg.Unit (set_mode `Start), "name Start a job manually";
+    "--tail", Arg.Unit (set_mode `Tail), "serial Tail job output";
     "--type", Arg.Set_string typ, "bool|int|float|string|unit Set the variable type";
     "--upload", Arg.Unit (set_mode `Upload), " Upload the script";
     "--variables", Arg.Unit (set_mode `Variables), " Display all variables and values";
@@ -220,6 +221,14 @@ Options:
     );
     start_job (List.hd args)
 
+  | Some `Tail ->
+    if List.length args != 1 then (
+      eprintf "whenjobs --tail serial\n";
+      suggest_help ();
+      exit 1
+    );
+    tail (List.hd args)
+
 and edit_file () =
   (* If there is no initial file, create an empty one containing the
    * tutorial.
@@ -421,6 +430,19 @@ and start_job name =
   );
   stop_client client
 
+  (* This only works for local.  If we ever make whenjobs work
+   * remotely we'll have to change the implementation to use
+   * the server.
+   *)
+and tail serial =
+  let client = start_client () in
+  let job = Whenproto_clnt.When.V1.get_job client serial in
+  stop_client client;
+  let cmd =
+    sprintf "tail -f %s/output.txt"
+      (Filename.quote job.Whenproto_aux.job_tmpdir) in
+  exit (Sys.command cmd)
+
 and unused_error args op =
   if args <> [] then (
     eprintf "whenjobs %s: unused parameters on the command line.\n" op;