diff options
| author | John Estabrook <jestabro@vyos.io> | 2025-12-08 13:23:01 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-12-08 13:23:01 -0600 |
| commit | f6c35930530cc72794a3f7c7488422ccb604b7fd (patch) | |
| tree | 5b372626f74d8413c2663bc7908e2a5c33d12809 /src | |
| parent | b4acb65d767c4af1f1df2b252ea9030735c08342 (diff) | |
| parent | 4028c234ce9e42ef76bcc5243fb0cf75aff09f9b (diff) | |
| download | vyconf-f6c35930530cc72794a3f7c7488422ccb604b7fd.tar.gz vyconf-f6c35930530cc72794a3f7c7488422ccb604b7fd.zip | |
Merge pull request #38 from jestabro/vyconf_cli-minor-fixes
T8074: minor fixes for vyconf_cli and removal of options now in vyconf_cli_compat
Diffstat (limited to 'src')
| -rw-r--r-- | src/vyconf_cli.ml | 37 |
1 files changed, 27 insertions, 10 deletions
diff --git a/src/vyconf_cli.ml b/src/vyconf_cli.ml index b2ee630..8563572 100644 --- a/src/vyconf_cli.ml +++ b/src/vyconf_cli.ml @@ -5,16 +5,12 @@ type op_t = | OpSet | OpDelete | OpDiscard - | OpShowConfig - | OpSessionChanged let op_of_string s = match s with | "vy_set" -> OpSet | "vy_delete" -> OpDelete | "vy_discard" -> OpDiscard - | "vy_show" -> OpShowConfig - | "vy_session_changed" -> OpSessionChanged | _ -> failwith (Printf.sprintf "Unknown operation %s" s) let config_format_of_string s = @@ -38,7 +34,12 @@ let in_cli_config_session () = | None -> false let get_session () = - let pid = Int32.of_int (Unix.getppid()) in + let pid = + try (* set for config session *) + Int32.of_string (Sys.getenv "SESSION_PID") + with Not_found -> + Int32.of_int (Unix.getppid()) + in let user = try Sys.getenv "USER" with Not_found -> "" @@ -75,8 +76,6 @@ let main op path = | OpSet -> set c path | OpDelete -> delete c path | OpDiscard -> discard c - | OpShowConfig -> show_config c path - | OpSessionChanged -> session_changed c end | Error e -> Error e |> Lwt.return in @@ -85,12 +84,30 @@ let main op path = close_session () |> Lwt.ignore_result in match result with - | Ok s -> let%lwt () = Lwt_io.write Lwt_io.stdout s in Lwt.return 0 - | Error e -> let%lwt () = Lwt_io.write Lwt_io.stderr (Printf.sprintf "%s\n" e) in Lwt.return 1 + | Ok s -> + begin + match s with + | "" -> Lwt.return 0 + | _ -> + let%lwt () = + Lwt_io.write Lwt_io.stdout (Printf.sprintf "%s\n" s) in Lwt.return 0 + end + | Error e -> + begin + match e with + | "" -> Lwt.return 1 + | _ -> + let%lwt () = + Lwt_io.write Lwt_io.stderr (Printf.sprintf "%s\n" e) in Lwt.return 1 + end let () = let path_list = Array.to_list (Array.sub Sys.argv 1 (Array.length Sys.argv - 1)) in let op_str = FilePath.basename Sys.argv.(0) in let op = op_of_string op_str in - let result = Lwt_main.run (main op path_list) in exit result + match op, path_list with + | OpSet, [] | OpDelete, [] -> + let () = print_endline "Must specify config path" in exit 1 + | _, _ -> + let result = Lwt_main.run (main op path_list) in exit result |
