mirror of
https://github.com/systemd/systemd.git
synced 2024-11-01 17:51:22 +03:00
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.
This commit is contained in:
parent
0f495e0123
commit
2e7e19cafc
@ -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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user