diff options
author | Daniil Baturin <daniil@vyos.io> | 2021-04-18 12:19:08 +0300 |
---|---|---|
committer | Daniil Baturin <daniil@vyos.io> | 2021-04-18 12:30:41 +0300 |
commit | f783ac068ec219c71255c3971028dc2b17ea9b62 (patch) | |
tree | 454b5150e6b7b7d396b2452d272bf548e09ac2e1 /src | |
parent | aa40543fc0fc27866bfef5d4cc6f34c33d7d47c8 (diff) | |
download | vyos-utils-f783ac068ec219c71255c3971028dc2b17ea9b62.tar.gz vyos-utils-f783ac068ec219c71255c3971028dc2b17ea9b62.zip |
Consistent formatting in validate-value.ml
Diffstat (limited to 'src')
-rw-r--r-- | src/validate_value.ml | 47 |
1 files changed, 23 insertions, 24 deletions
diff --git a/src/validate_value.ml b/src/validate_value.ml index 02cd15a..0b4148f 100644 --- a/src/validate_value.ml +++ b/src/validate_value.ml @@ -1,36 +1,35 @@ type check = Regex of string | Exec of string let validate_value buf value_constraint value = - match value_constraint with - | Regex s -> - (try - let _ = Pcre.exec ~pat:s value in true - with Not_found -> false) - | Exec c -> - (* XXX: Unix.open_process_in is "shelling out", which is a bad idea on multiple levels, - especially when the input comes directly from the user... - We should do something about it. - *) - let chan = Unix.open_process_in (Printf.sprintf "%s \'%s\' 2>&1" c value) in - let out = try CCIO.read_all chan with _ -> "" in - let result = Unix.close_process_in chan in - match result with - | Unix.WEXITED 0 -> true - | Unix.WEXITED 127 -> - let () = Printf.printf "Could not execute validator %s" c in - false - | _ -> - let () = Buffer.add_string buf out; Buffer.add_string buf "\n" in - false + match value_constraint with + | Regex s -> + (try let _ = Pcre.exec ~pat:s value in true + with Not_found -> false) + | Exec c -> + (* XXX: Unix.open_process_in is "shelling out", which is a bad idea on multiple levels, + especially when the input comes directly from the user... + We should do something about it. + *) + let chan = Unix.open_process_in (Printf.sprintf "%s \'%s\' 2>&1" c value) in + let out = try CCIO.read_all chan with _ -> "" in + let result = Unix.close_process_in chan in + match result with + | Unix.WEXITED 0 -> true + | Unix.WEXITED 127 -> + let () = Printf.printf "Could not execute validator %s" c in + false + | _ -> + let () = Buffer.add_string buf out; Buffer.add_string buf "\n" in + false let value = ref "" let checks = ref [] let args = [ - ("--regex", Arg.String (fun s -> checks := (Regex s) :: !checks), "Check the value against a regex"); - ("--exec", Arg.String (fun s -> checks := (Exec s) :: !checks), "Check the value against an external command"); - ("--value", Arg.String (fun s -> value := s), "Value to check"); + ("--regex", Arg.String (fun s -> checks := (Regex s) :: !checks), "Check the value against a regex"); + ("--exec", Arg.String (fun s -> checks := (Exec s) :: !checks), "Check the value against an external command"); + ("--value", Arg.String (fun s -> value := s), "Value to check"); ] let usage = Printf.sprintf "Usage: %s [OPTIONS] <number>" Sys.argv.(0) |