From 3d48fedd6df4da6e10c56eb9f8d313091d2d6916 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Sat, 10 Mar 2012 12:13:40 +0000 Subject: [PATCH] Simplify code in the whenjobs tool by creating nr_args, arg1 variables. --- tools/whenjobs.ml | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/tools/whenjobs.ml b/tools/whenjobs.ml index be38f67..ff166a6 100644 --- a/tools/whenjobs.ml +++ b/tools/whenjobs.ml @@ -143,6 +143,8 @@ Options: | t -> eprintf "whenjobs: --type: unknown type (%s)\n" t; exit 1 in + let nr_args = List.length args in + let arg1 = match args with [] -> "" | a::_ -> a in (* Depending on the selected mode, perform a different action. *) match mode with @@ -173,12 +175,12 @@ Options: set_variable (List.hd args) (List.hd (List.tl args)) typ | Some `Get -> - if List.length args != 1 then ( + if nr_args != 1 then ( eprintf "whenjobs --get variable\n"; suggest_help (); exit 1 ); - get_variable (List.hd args) + get_variable arg1 | Some `Variables -> unused_error args "--variables"; @@ -205,29 +207,29 @@ Options: jobs () | Some `Cancel -> - if List.length args != 1 then ( + if nr_args != 1 then ( eprintf "whenjobs --cancel serial\n"; suggest_help (); exit 1 ); - cancel_job (List.hd args) + cancel_job arg1 | Some `Start -> - if List.length args != 1 then ( + if nr_args != 1 then ( eprintf "whenjobs --start jobname\n"; eprintf "If 'value' contains spaces, you may need to quote it.\n"; suggest_help (); exit 1 ); - start_job (List.hd args) + start_job arg1 | Some `Tail -> - if List.length args != 1 then ( + if nr_args != 1 then ( eprintf "whenjobs --tail serial\n"; suggest_help (); exit 1 ); - tail (List.hd args) + tail arg1 and edit_file () = (* If there is no initial file, create an empty one containing the -- 1.8.3.1