Improve program usage output.
* include/mailutils/opt.h (MU_PARSEOPT_SPECIAL_ARGS): New flag. (mu_parseopt)<po_special_args>: New field. * libmailutils/opt/help.c (option_summary) (print_program_usage): Print po_special_args, if defined. * libmailutils/opt/opt.c (parseopt_init): Initialize po_special_args unless MU_PARSEOPT_SPECIAL_ARGS is set. MH: Advertise [+FOLDER] special argument if the -folder option is declared. * mh/mh_getopt.c (folder_option): Bugfix: -folder takes argument. (mh_getopt): Set po_special_args if the -folder option is declared. * mh/inc.c: Fix arg_doc. * mh/mhpath.c: Likewise. * mh/repl.c: Likewise. * mh/rmf.c: Likewise. * mh/rmm.c: Likewise. * mh/scan.c: Likewise. * mh/show.c: Likewise.
Showing
11 changed files
with
48 additions
and
17 deletions
... | @@ -109,6 +109,8 @@ struct mu_option_cache | ... | @@ -109,6 +109,8 @@ struct mu_option_cache |
109 | #define MU_PARSEOPT_SINGLE_DASH 0x02000000 | 109 | #define MU_PARSEOPT_SINGLE_DASH 0x02000000 |
110 | /* Negation prefix is set */ | 110 | /* Negation prefix is set */ |
111 | #define MU_PARSEOPT_NEGATION 0x04000000 | 111 | #define MU_PARSEOPT_NEGATION 0x04000000 |
112 | /* po_special_args is set */ | ||
113 | #define MU_PARSEOPT_SPECIAL_ARGS 0x08000000 | ||
112 | 114 | ||
113 | /* Reuse mu_parseopt struct initialized previously */ | 115 | /* Reuse mu_parseopt struct initialized previously */ |
114 | #define MU_PARSEOPT_REUSE 0x80000000 | 116 | #define MU_PARSEOPT_REUSE 0x80000000 |
... | @@ -131,8 +133,9 @@ struct mu_parseopt | ... | @@ -131,8 +133,9 @@ struct mu_parseopt |
131 | 133 | ||
132 | /* Informational: */ | 134 | /* Informational: */ |
133 | char const *po_prog_name; | 135 | char const *po_prog_name; |
134 | char const *po_prog_doc; | 136 | char const *po_prog_doc; |
135 | char const **po_prog_args; | 137 | char const **po_prog_args; |
138 | char const *po_special_args; /* Special option-like arguments */ | ||
136 | char const *po_bug_address; | 139 | char const *po_bug_address; |
137 | char const *po_package_name; | 140 | char const *po_package_name; |
138 | char const *po_package_url; | 141 | char const *po_package_url; | ... | ... |
... | @@ -523,6 +523,9 @@ option_summary (struct mu_parseopt *po, mu_stream_t str) | ... | @@ -523,6 +523,9 @@ option_summary (struct mu_parseopt *po, mu_stream_t str) |
523 | } | 523 | } |
524 | } | 524 | } |
525 | 525 | ||
526 | if (po->po_special_args) | ||
527 | mu_stream_printf (str, " %s", gettext (po->po_special_args)); | ||
528 | |||
526 | free (idxbuf); | 529 | free (idxbuf); |
527 | } | 530 | } |
528 | 531 | ||
... | @@ -535,10 +538,7 @@ print_program_usage (struct mu_parseopt *po, int optsum, mu_stream_t str) | ... | @@ -535,10 +538,7 @@ print_program_usage (struct mu_parseopt *po, int optsum, mu_stream_t str) |
535 | 538 | ||
536 | usage_text = _("Usage:"); | 539 | usage_text = _("Usage:"); |
537 | 540 | ||
538 | if (po->po_flags & MU_PARSEOPT_PROG_ARGS) | 541 | arg_text = po->po_prog_args; |
539 | arg_text = po->po_prog_args; | ||
540 | else | ||
541 | arg_text = NULL; | ||
542 | i = 0; | 542 | i = 0; |
543 | 543 | ||
544 | do | 544 | do |
... | @@ -552,7 +552,11 @@ print_program_usage (struct mu_parseopt *po, int optsum, mu_stream_t str) | ... | @@ -552,7 +552,11 @@ print_program_usage (struct mu_parseopt *po, int optsum, mu_stream_t str) |
552 | optsum = 0; | 552 | optsum = 0; |
553 | } | 553 | } |
554 | else | 554 | else |
555 | mu_stream_printf (str, "[%s...]", _("OPTION")); | 555 | { |
556 | mu_stream_printf (str, "[%s...]", _("OPTION")); | ||
557 | if (po->po_special_args) | ||
558 | mu_stream_printf (str, " %s", gettext (po->po_special_args)); | ||
559 | } | ||
556 | 560 | ||
557 | if (arg_text) | 561 | if (arg_text) |
558 | { | 562 | { | ... | ... |
... | @@ -578,6 +578,8 @@ parseopt_init (struct mu_parseopt *po, struct mu_option **options, | ... | @@ -578,6 +578,8 @@ parseopt_init (struct mu_parseopt *po, struct mu_option **options, |
578 | po->po_prog_doc = NULL; | 578 | po->po_prog_doc = NULL; |
579 | if (!(flags & MU_PARSEOPT_PROG_ARGS)) | 579 | if (!(flags & MU_PARSEOPT_PROG_ARGS)) |
580 | po->po_prog_args = NULL; | 580 | po->po_prog_args = NULL; |
581 | if (!(flags & MU_PARSEOPT_SPECIAL_ARGS)) | ||
582 | po->po_special_args = NULL; | ||
581 | if (!(flags & MU_PARSEOPT_BUG_ADDRESS)) | 583 | if (!(flags & MU_PARSEOPT_BUG_ADDRESS)) |
582 | po->po_bug_address = NULL; | 584 | po->po_bug_address = NULL; |
583 | if (!(flags & MU_PARSEOPT_PACKAGE_NAME)) | 585 | if (!(flags & MU_PARSEOPT_PACKAGE_NAME)) | ... | ... |
... | @@ -26,7 +26,6 @@ static char extra_doc[] = N_("Debug flags are:\n\ | ... | @@ -26,7 +26,6 @@ static char extra_doc[] = N_("Debug flags are:\n\ |
26 | t - sieve trace (MU_SIEVE_DEBUG_TRACE)\n\ | 26 | t - sieve trace (MU_SIEVE_DEBUG_TRACE)\n\ |
27 | i - sieve instructions trace (MU_SIEVE_DEBUG_INSTR)\n\ | 27 | i - sieve instructions trace (MU_SIEVE_DEBUG_INSTR)\n\ |
28 | l - sieve action logs"); | 28 | l - sieve action logs"); |
29 | static char args_doc[] = N_("[+FOLDER]"); | ||
30 | 29 | ||
31 | static char *format_str = mh_list_format; | 30 | static char *format_str = mh_list_format; |
32 | static int width = 80; | 31 | static int width = 80; |
... | @@ -345,7 +344,7 @@ main (int argc, char **argv) | ... | @@ -345,7 +344,7 @@ main (int argc, char **argv) |
345 | size_t lastseen; | 344 | size_t lastseen; |
346 | const char *unseen_seq; | 345 | const char *unseen_seq; |
347 | 346 | ||
348 | mh_getopt (&argc, &argv, options, 0, args_doc, prog_doc, extra_doc); | 347 | mh_getopt (&argc, &argv, options, 0, NULL, prog_doc, extra_doc); |
349 | if (!append_folder) | 348 | if (!append_folder) |
350 | append_folder = mh_global_profile_get ("Inbox", "inbox"); | 349 | append_folder = mh_global_profile_get ("Inbox", "inbox"); |
351 | if (argc) | 350 | if (argc) | ... | ... |
... | @@ -135,7 +135,7 @@ mh_opt_set_folder (struct mu_parseopt *po, struct mu_option *opt, | ... | @@ -135,7 +135,7 @@ mh_opt_set_folder (struct mu_parseopt *po, struct mu_option *opt, |
135 | } | 135 | } |
136 | 136 | ||
137 | static struct mu_option folder_option[] = { | 137 | static struct mu_option folder_option[] = { |
138 | { "folder", 0, NULL, MU_OPTION_DEFAULT, | 138 | { "folder", 0, N_("FOLDER"), MU_OPTION_DEFAULT, |
139 | N_("set current folder"), | 139 | N_("set current folder"), |
140 | mu_c_string, NULL, mh_opt_set_folder }, | 140 | mu_c_string, NULL, mh_opt_set_folder }, |
141 | MU_OPTION_END | 141 | MU_OPTION_END |
... | @@ -164,6 +164,19 @@ There is NO WARRANTY, to the extent permitted by law.\n\ | ... | @@ -164,6 +164,19 @@ There is NO WARRANTY, to the extent permitted by law.\n\ |
164 | ")); | 164 | ")); |
165 | } | 165 | } |
166 | 166 | ||
167 | static int | ||
168 | has_folder_option (struct mu_option *opt) | ||
169 | { | ||
170 | while (!MU_OPTION_IS_END (opt)) | ||
171 | { | ||
172 | if (MU_OPTION_IS_VALID_LONG_OPTION (opt) | ||
173 | && strcmp (opt->opt_long, "folder") == 0) | ||
174 | return 1; | ||
175 | ++opt; | ||
176 | } | ||
177 | return 0; | ||
178 | } | ||
179 | |||
167 | void | 180 | void |
168 | mh_getopt (int *pargc, char ***pargv, struct mu_option *options, | 181 | mh_getopt (int *pargc, char ***pargv, struct mu_option *options, |
169 | int mhflags, | 182 | int mhflags, |
... | @@ -184,6 +197,12 @@ mh_getopt (int *pargc, char ***pargv, struct mu_option *options, | ... | @@ -184,6 +197,12 @@ mh_getopt (int *pargc, char ***pargv, struct mu_option *options, |
184 | po.po_negation = "no"; | 197 | po.po_negation = "no"; |
185 | flags |= MU_PARSEOPT_NEGATION; | 198 | flags |= MU_PARSEOPT_NEGATION; |
186 | 199 | ||
200 | if ((mhflags & MH_GETOPT_DEFAULT_FOLDER) || has_folder_option (options)) | ||
201 | { | ||
202 | po.po_special_args = N_("[+FOLDER]"); | ||
203 | flags |= MU_PARSEOPT_SPECIAL_ARGS; | ||
204 | } | ||
205 | |||
187 | if (argdoc) | 206 | if (argdoc) |
188 | { | 207 | { |
189 | args[0] = argdoc; | 208 | args[0] = argdoc; |
... | @@ -248,7 +267,12 @@ mh_getopt (int *pargc, char ***pargv, struct mu_option *options, | ... | @@ -248,7 +267,12 @@ mh_getopt (int *pargc, char ***pargv, struct mu_option *options, |
248 | 267 | ||
249 | if (!argdoc && argc) | 268 | if (!argdoc && argc) |
250 | { | 269 | { |
251 | mu_error (_("Extra arguments")); | 270 | mu_diag_init (); |
271 | mu_stream_printf (mu_strerr, "\033s<%d>", MU_DIAG_ERROR); | ||
272 | mu_stream_printf (mu_strerr, "%s", _("unrecognized extra arguments:")); | ||
273 | for (i = 0; i < argc; i++) | ||
274 | mu_stream_printf (mu_strerr, " %s", argv[i]); | ||
275 | mu_stream_write (mu_strerr, "\n", 1, NULL); | ||
252 | exit (1); | 276 | exit (1); |
253 | } | 277 | } |
254 | 278 | ... | ... |
... | @@ -20,7 +20,7 @@ | ... | @@ -20,7 +20,7 @@ |
20 | #include <mh.h> | 20 | #include <mh.h> |
21 | 21 | ||
22 | static char prog_doc[] = N_("Print full pathnames of GNU MH messages and folders"); | 22 | static char prog_doc[] = N_("Print full pathnames of GNU MH messages and folders"); |
23 | static char args_doc[] = N_("[+FOLDER] [MSGLIST]"); | 23 | static char args_doc[] = N_("[MSGLIST]"); |
24 | 24 | ||
25 | static int | 25 | static int |
26 | mhpath (size_t num, mu_message_t msg, void *data) | 26 | mhpath (size_t num, mu_message_t msg, void *data) | ... | ... |
... | @@ -23,7 +23,7 @@ | ... | @@ -23,7 +23,7 @@ |
23 | #include <unistd.h> | 23 | #include <unistd.h> |
24 | 24 | ||
25 | static char prog_doc[] = N_("Reply to a message"); | 25 | static char prog_doc[] = N_("Reply to a message"); |
26 | static char args_doc[] = N_("[+FOLDER] [MESSAGE]"); | 26 | static char args_doc[] = N_("[MESSAGE]"); |
27 | 27 | ||
28 | static char *format_str = NULL; | 28 | static char *format_str = NULL; |
29 | static mh_format_t format; | 29 | static mh_format_t format; | ... | ... |
... | @@ -29,7 +29,6 @@ | ... | @@ -29,7 +29,6 @@ |
29 | #include <dirent.h> | 29 | #include <dirent.h> |
30 | 30 | ||
31 | static char prog_doc[] = N_("Remove a GNU MH folder"); | 31 | static char prog_doc[] = N_("Remove a GNU MH folder"); |
32 | static char args_doc[] = N_("[+FOLDER]"); | ||
33 | 32 | ||
34 | int explicit_folder; /* Was the folder explicitly given */ | 33 | int explicit_folder; /* Was the folder explicitly given */ |
35 | int interactive; /* Ask for confirmation before deleting */ | 34 | int interactive; /* Ask for confirmation before deleting */ |
... | @@ -150,7 +149,7 @@ main (int argc, char **argv) | ... | @@ -150,7 +149,7 @@ main (int argc, char **argv) |
150 | int status; | 149 | int status; |
151 | char *name; | 150 | char *name; |
152 | 151 | ||
153 | mh_getopt (&argc, &argv, options, 0, args_doc, prog_doc, NULL); | 152 | mh_getopt (&argc, &argv, options, 0, NULL, prog_doc, NULL); |
154 | 153 | ||
155 | cur_folder_path = current_folder_path (); | 154 | cur_folder_path = current_folder_path (); |
156 | 155 | ... | ... |
... | @@ -20,7 +20,7 @@ | ... | @@ -20,7 +20,7 @@ |
20 | #include <mh.h> | 20 | #include <mh.h> |
21 | 21 | ||
22 | static char prog_doc[] = N_("Remove messages"); | 22 | static char prog_doc[] = N_("Remove messages"); |
23 | static char args_doc[] = N_("[+FOLDER] [MSGLIST]"); | 23 | static char args_doc[] = N_("[MSGLIST]"); |
24 | 24 | ||
25 | static int | 25 | static int |
26 | rmm (size_t num, mu_message_t msg, void *data) | 26 | rmm (size_t num, mu_message_t msg, void *data) | ... | ... |
... | @@ -27,7 +27,7 @@ | ... | @@ -27,7 +27,7 @@ |
27 | #include <mailutils/observer.h> | 27 | #include <mailutils/observer.h> |
28 | 28 | ||
29 | static char prog_doc[] = N_("Produce a one line per message scan listing"); | 29 | static char prog_doc[] = N_("Produce a one line per message scan listing"); |
30 | static char args_doc[] = N_("[+FOLDER] [MSGLIST]"); | 30 | static char args_doc[] = N_("[MSGLIST]"); |
31 | 31 | ||
32 | static int clear; | 32 | static int clear; |
33 | static char *format_str = mh_list_format; | 33 | static char *format_str = mh_list_format; | ... | ... |
... | @@ -20,7 +20,7 @@ | ... | @@ -20,7 +20,7 @@ |
20 | #include <mh.h> | 20 | #include <mh.h> |
21 | 21 | ||
22 | static char prog_doc[] = N_("Display GNU MH messages"); | 22 | static char prog_doc[] = N_("Display GNU MH messages"); |
23 | static char args_doc[] = N_("[+FOLDER] [MSGLIST]"); | 23 | static char args_doc[] = N_("[MSGLIST]"); |
24 | 24 | ||
25 | int use_draft; | 25 | int use_draft; |
26 | int use_showproc = 1; | 26 | int use_showproc = 1; | ... | ... |
-
Please register or sign in to post a comment