"--variables", Arg.Unit (set_mode `Variables), " Display all variables and values";
"-V", Arg.Unit display_version, " Display version number and exit";
"--version", Arg.Unit display_version, " Display version number and exit";
+ "--whisper", Arg.Unit (set_mode `Whisper), " Set the variable, quietly";
] in
(* anon_fun normally just collects up the anonymous arguments as
* strings, and most modes just use 'args' as a list of strings.
- * However for `Set and `Test modes we need to record the type of
- * each argument as well, so we keep that in a separate list
+ * However for `Set, `Test and `Whisper modes we need to record the
+ * type of each argument as well, so we keep that in a separate list
* (argtypes).
*)
let argtypes = ref [] in
if nr_args > 0 then
test_variables argtypes
+ | Some `Whisper ->
+ if nr_args > 0 then
+ whisper_variables argtypes
+
| Some `Get ->
if nr_args != 1 then (
eprintf "whenjobs --get variable\n";
let i =
try String.index def '='
with Not_found ->
- eprintf "whenjobs: set: missing = sign in variable definition\n";
+ eprintf "whenjobs: test: missing = sign in variable definition\n";
suggest_help ();
exit 1 in
let name = String.sub def 0 i in
Array.iter print_endline jobnames
+and whisper_variables argtypes =
+ let vars = List.map (
+ fun (def, typ) ->
+ (* 'def' should have the form "name=value". The value part may
+ * be missing, but the equals sign is required.
+ *)
+ let i =
+ try String.index def '='
+ with Not_found ->
+ eprintf "whenjobs: whisper: missing = sign in variable definition\n";
+ suggest_help ();
+ exit 1 in
+ let name = String.sub def 0 i in
+ let value = String.sub def (i+1) (String.length def - (i+1)) in
+ let value = value_of_string value typ in
+ { Whenproto_aux.sv_name = name; sv_value = value }
+ ) argtypes in
+ let vars = Array.of_list vars in
+
+ let client = start_client () in
+ (match Whenproto_clnt.When.V1.whisper_variables client vars with
+ | `ok -> ()
+ | `error msg ->
+ eprintf "whenjobs: whisper: %s\n" msg;
+ suggest_check_server_logs ();
+ exit 1
+ );
+ stop_client client
+
and get_variable name =
let client = start_client () in
let value = Whenproto_clnt.When.V1.get_variable client name in