From aa97c4f9f28472d7a10c0017fdb9461febbcc604 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophane=20Hufschmitt?= Date: Mon, 11 Apr 2022 10:20:37 +0200 Subject: [PATCH] find-roots: Fix `--help` and invalid cli flags - Make `--help` and `-h` valid cli flags that show the (short) help - Prevent the program from segfaulting when an invalid option is passed --- src/nix-find-roots/main.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/nix-find-roots/main.cc b/src/nix-find-roots/main.cc index 05697356d..b6da5f182 100644 --- a/src/nix-find-roots/main.cc +++ b/src/nix-find-roots/main.cc @@ -30,17 +30,20 @@ TracerConfig parseCmdLine(int argc, char** argv) { "socket_path", required_argument, 0, 'l' }, { "store_dir", required_argument, 0, 's' }, { "state_dir", required_argument, 0, 'd' }, + { "help", no_argument, 0, 'h' }, + { 0, 0, 0, 0 }, }; int option_index = 0; int opt_char; - while((opt_char = getopt_long(argc, argv, "vd:s:l:", + while((opt_char = getopt_long(argc, argv, "vd:s:l:h", long_options, &option_index)) != -1) { switch (opt_char) { case 0: break; break; case '?': + case 'h': usage(); break; case 'v':