]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
systemctl: be nice to users and give hint how to specify "-.mount"
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 6 Dec 2018 14:04:14 +0000 (15:04 +0100)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 7 Dec 2018 01:49:03 +0000 (02:49 +0100)
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.

src/systemctl/systemctl.c

index 9e549db9444bb0e717331dcf98ae7ddbb96c2397..19f49a5ae624e7a1eb4a1dae06e515e4cd9c0718 100644 (file)
@@ -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;