From: Zbigniew Jędrzejewski-Szmek Date: Thu, 6 Dec 2018 14:04:14 +0000 (+0100) Subject: systemctl: be nice to users and give hint how to specify "-.mount" X-Git-Tag: v240~119 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2e7e19cafc01fcfa113be3b63d5f8b374e02a4a4;p=thirdparty%2Fsystemd.git systemctl: be nice to users and give hint how to specify "-.mount" https://bugzilla.redhat.com/show_bug.cgi?id=1656639 Using "--" is a trick that is hard to discover. Let's give users a hint: $ build/systemctl status -.service build/systemctl: invalid option -- '.' Hint: to specify units starting with a dash, use "--": build/systemctl [OPTIONS...] {COMMAND} -- -.service ... I use program_invocation_name because that's what getopt seems to use. "::" is used in the option string so that getopt doesn't complain about a missing argument in case somebody passes "-." as the argument. After all "." is not a real option. --- diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c index 9e549db9444..19f49a5ae62 100644 --- a/src/systemctl/systemctl.c +++ b/src/systemctl/systemctl.c @@ -7573,7 +7573,7 @@ static int systemctl_parse_argv(int argc, char *argv[]) { /* we default to allowing interactive authorization only in systemctl (not in the legacy commands) */ arg_ask_password = true; - while ((c = getopt_long(argc, argv, "ht:p:alqfs:H:M:n:o:ir", options, NULL)) >= 0) + while ((c = getopt_long(argc, argv, "ht:p:alqfs:H:M:n:o:ir.::", options, NULL)) >= 0) switch (c) { @@ -7889,6 +7889,14 @@ static int systemctl_parse_argv(int argc, char *argv[]) { return log_oom(); break; + case '.': + /* Output an error mimicking getopt, and print a hint afterwards */ + log_error("%s: invalid option -- '.'", program_invocation_name); + log_notice("Hint: to specify units starting with a dash, use \"--\":\n" + " %s [OPTIONS...] {COMMAND} -- -.%s ...", + program_invocation_name, optarg ?: "mount"); + _fallthrough_; + case '?': return -EINVAL;