diff options
author | John Estabrook <jestabro@vyos.io> | 2022-12-12 10:58:55 -0600 |
---|---|---|
committer | Christian Breunig <christian@breunig.cc> | 2023-01-21 19:48:01 +0100 |
commit | ebd356b218ad4261c9af1bc78d8f40c36b074ec1 (patch) | |
tree | 412c4400207a43d2527aea1990995374cb66c13b | |
parent | 33becfe79f17f6c1f81c908fd74127be313cff25 (diff) | |
download | vyos-utils-ebd356b218ad4261c9af1bc78d8f40c36b074ec1.tar.gz vyos-utils-ebd356b218ad4261c9af1bc78d8f40c36b074ec1.zip |
validators: T4875: add option lookup-path to cat with file/dir arg
(cherry picked from commit 3883bb64a45794904f042e2f1e4458eb4700de8b)
-rw-r--r-- | src/file_path.ml | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/file_path.ml b/src/file_path.ml index 8c05ffd..ea3068c 100644 --- a/src/file_path.ml +++ b/src/file_path.ml @@ -1,12 +1,14 @@ type opts = { must_be_file : bool; parent : string option; + lookup_path : string option; strict : bool; } let default_opts = { must_be_file = true; parent = None; + lookup_path = None; strict = false } @@ -18,6 +20,7 @@ let args = [ ("--file", Arg.Unit (fun () -> opts := {!opts with must_be_file=true}), "Path must point to a file and not a directory (default)"); ("--directory", Arg.Unit (fun () -> opts := {!opts with must_be_file=false}), "Path must point to a directory"); ("--parent-dir", Arg.String (fun s -> opts := {!opts with parent=(Some s)}), "Path must be inside specific parent directory"); + ("--lookup-path", Arg.String (fun s -> opts := {!opts with lookup_path=(Some s)}), "Prefix path argument with lookup path"); ("--strict", Arg.Unit (fun () -> opts := {!opts with strict=true}), "Treat warnings as errors"); ] let usage = Printf.sprintf "Usage: %s [OPTIONS] <path>" Sys.argv.(0) @@ -30,8 +33,12 @@ let fail msg = exit 1 let () = - let path = !path_arg in let opts = !opts in + let path = + match opts.lookup_path with + | None -> !path_arg + | Some lookup_path -> FilePath.concat lookup_path !path_arg + in (* First, check if the file/dir path exists at all. *) let exists = FileUtil.test FileUtil.Exists path in if not exists then Printf.ksprintf fail {|Incorrect path %s: no such file or directory|} path else |