diff options
author | Daniil Baturin <daniil@vyos.io> | 2023-10-07 23:38:48 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-07 23:38:48 +0100 |
commit | 0d57cc9a266fe8d6fc87df5a769f42b4a45c7221 (patch) | |
tree | a71b0798c309f723ed289478b6627ac8c700bc3f | |
parent | 200493d536ffaf6c54e218dead8253cdb91d2b5a (diff) | |
parent | d0c65466b847e6111844bdc8bc6a0f9dd285bb53 (diff) | |
download | vyos-utils-0d57cc9a266fe8d6fc87df5a769f42b4a45c7221.tar.gz vyos-utils-0d57cc9a266fe8d6fc87df5a769f42b4a45c7221.zip |
Merge pull request #18 from jestabro/T5638-sagitta
T5638 sagitta
-rw-r--r-- | src/numeric.ml | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/src/numeric.ml b/src/numeric.ml index a3c5d11..0c75f83 100644 --- a/src/numeric.ml +++ b/src/numeric.ml @@ -10,6 +10,7 @@ type options = { not_values: string list; relative: bool; allow_range: bool; + require_range: bool; } let default_opts = { @@ -21,6 +22,7 @@ let default_opts = { not_values = []; relative = false; allow_range = false; + require_range = false; } let opts = ref default_opts @@ -36,6 +38,7 @@ let args = [ ("--float", Arg.Unit (fun () -> opts := {!opts with allow_float=true}), "Allow floating-point numbers"); ("--relative", Arg.Unit (fun () -> opts := {!opts with relative=true}), "Allow relative increment/decrement (+/-N)"); ("--allow-range", Arg.Unit (fun () -> opts := {!opts with allow_range=true}), "Allow the argument to be a range rather than a single number"); + ("--require-range", Arg.Unit (fun () -> opts := {!opts with require_range=true; allow_range=true}), "Require the argument to be a range rather than a single number"); ("--", Arg.Rest (fun s -> number_arg := s), "Interpret next item as an argument"); ] let usage = Printf.sprintf "Usage: %s [OPTIONS] <number>|<range>" Sys.argv.(0) @@ -146,6 +149,7 @@ let check_not_ranges opts m = let check_not_values opts m = let excluded_values = List.map (number_of_string opts) opts.not_values in + if excluded_values = [] then () else match m with | Range_float _ -> Printf.ksprintf failwith "--not-value cannot be used with ranges" | Number_float num -> @@ -158,7 +162,9 @@ let check_not_values opts m = let check_argument_type opts m = match m with - | Number_float _ -> () + | Number_float _ -> + if opts.require_range then Printf.ksprintf failwith "Value must be a range, not a number" + else () | Range_float _ -> if opts.allow_range then () else Printf.ksprintf failwith "Value must be a number, not a range" |