diff options
author | Franck Bui <fbui@suse.com> | 2016-11-07 17:14:59 +0100 |
---|---|---|
committer | Franck Bui <fbui@suse.com> | 2016-11-17 18:16:50 +0100 |
commit | d172b175f6d43d68929975e3baa3837da677bc68 (patch) | |
tree | e15fea1347829f66f7f6fdd75eef6a2e7c15f5d0 | |
parent | core: limit the length of the confirmation question (diff) | |
download | systemd-d172b175f6d43d68929975e3baa3837da677bc68.tar.xz systemd-d172b175f6d43d68929975e3baa3837da677bc68.zip |
core: rework the confirmation spawn prompt
Previously it was "[Yes, Fail, Skip]" which is pretty misleading because it
suggests that the whole word needs to be entered instead of a single char.
Also this won't fit well when we'll extend the number of choices.
This patch addresses this by changing the choice hint with "[y, f, s – h for help]"
so it's now clear that a single letter has to be entered.
It also introduces a new choice 'h' which describes all possible choices since
a single letter can be not descriptive enough for new users.
It also allow to stick with the same hint string regardless of how
many choices we will support.
-rw-r--r-- | NEWS | 1 | ||||
-rw-r--r-- | src/core/execute.c | 47 |
2 files changed, 29 insertions, 19 deletions
@@ -6,6 +6,7 @@ CHANGES WITH 233 in spe following choices: (f)ail, don't execute the command and pretend it failed + (h)elp (s)kip, don't execute the command and pretend it succeeded (y)es, execute the command diff --git a/src/core/execute.c b/src/core/execute.c index 0273b1966f..65ba9acf7a 100644 --- a/src/core/execute.c +++ b/src/core/execute.c @@ -739,27 +739,36 @@ static int ask_for_confirmation(const char *vc, const char *cmdline) { goto restore_stdio; } - r = ask_char(&c, "yfs", "Execute %s? [Yes, Fail, Skip] ", e); - if (r < 0) { - write_confirm_error_fd(r, STDOUT_FILENO); - r = CONFIRM_EXECUTE; - goto restore_stdio; - } + for (;;) { + r = ask_char(&c, "yfsh", "Execute %s? [y, f, s – h for help] ", e); + if (r < 0) { + write_confirm_error_fd(r, STDOUT_FILENO); + r = CONFIRM_EXECUTE; + goto restore_stdio; + } - switch (c) { - case 'f': - printf("Failing execution.\n"); - r = CONFIRM_PRETEND_FAILURE; - break; - case 's': - printf("Skipping execution.\n"); - r = CONFIRM_PRETEND_SUCCESS; - break; - case 'y': - r = CONFIRM_EXECUTE; + switch (c) { + case 'f': + printf("Failing execution.\n"); + r = CONFIRM_PRETEND_FAILURE; + break; + case 'h': + printf(" f - fail, don't execute the command and pretend it failed\n" + " h - help\n" + " s - skip, don't execute the command and pretend it succeeded\n" + " y - yes, execute the command\n"); + continue; + case 's': + printf("Skipping execution.\n"); + r = CONFIRM_PRETEND_SUCCESS; + break; + case 'y': + r = CONFIRM_EXECUTE; + break; + default: + assert_not_reached("Unhandled choice"); + } break; - default: - assert_not_reached("Unhandled choice"); } restore_stdio: |