From d2978d7c37121fdc93ed8bb44cae01ec351d1f58 Mon Sep 17 00:00:00 2001 From: Daniil Baturin Date: Fri, 6 Oct 2023 16:59:16 +0100 Subject: numeric: T5638: Do not complain about range arguments in check_not_value when it's not necessary (i.e., when no actual --not-value options are given) (cherry picked from commit ba5e5638c15914c0b1bb3d61942f64046b38efd6) --- src/numeric.ml | 1 + 1 file changed, 1 insertion(+) (limited to 'src') diff --git a/src/numeric.ml b/src/numeric.ml index a3c5d11..f27c1ee 100644 --- a/src/numeric.ml +++ b/src/numeric.ml @@ -146,6 +146,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 -> -- cgit v1.2.3 From d0c65466b847e6111844bdc8bc6a0f9dd285bb53 Mon Sep 17 00:00:00 2001 From: Daniil Baturin Date: Fri, 6 Oct 2023 17:01:28 +0100 Subject: numeric: T5638: add --require-range (cherry picked from commit 4a18740024573d6c6f459053a8902ad00fcfaa60) --- src/numeric.ml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/numeric.ml b/src/numeric.ml index f27c1ee..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] |" Sys.argv.(0) @@ -159,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" -- cgit v1.2.3