core: rework the confirmation spawn prompt
authorFranck Bui <fbui@suse.com>
Mon, 7 Nov 2016 16:14:59 +0000 (17:14 +0100)
committerFranck Bui <fbui@suse.com>
Thu, 17 Nov 2016 17:16:50 +0000 (18:16 +0100)
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.

NEWS
src/core/execute.c

diff --git a/NEWS b/NEWS
index fbd9afa..fde3d6c 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -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
 
index 0273b19..65ba9ac 100644 (file)
@@ -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: