Commit 4872fc4f 4872fc4fb478af6c718fad0a43004fdbebc53fc0 by Sergey Poznyakoff

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.
1 parent cd577bf9
......@@ -109,6 +109,8 @@ struct mu_option_cache
#define MU_PARSEOPT_SINGLE_DASH 0x02000000
/* Negation prefix is set */
#define MU_PARSEOPT_NEGATION 0x04000000
/* po_special_args is set */
#define MU_PARSEOPT_SPECIAL_ARGS 0x08000000
/* Reuse mu_parseopt struct initialized previously */
#define MU_PARSEOPT_REUSE 0x80000000
......@@ -131,8 +133,9 @@ struct mu_parseopt
/* Informational: */
char const *po_prog_name;
char const *po_prog_doc;
char const *po_prog_doc;
char const **po_prog_args;
char const *po_special_args; /* Special option-like arguments */
char const *po_bug_address;
char const *po_package_name;
char const *po_package_url;
......
......@@ -523,6 +523,9 @@ option_summary (struct mu_parseopt *po, mu_stream_t str)
}
}
if (po->po_special_args)
mu_stream_printf (str, " %s", gettext (po->po_special_args));
free (idxbuf);
}
......@@ -535,10 +538,7 @@ print_program_usage (struct mu_parseopt *po, int optsum, mu_stream_t str)
usage_text = _("Usage:");
if (po->po_flags & MU_PARSEOPT_PROG_ARGS)
arg_text = po->po_prog_args;
else
arg_text = NULL;
arg_text = po->po_prog_args;
i = 0;
do
......@@ -552,7 +552,11 @@ print_program_usage (struct mu_parseopt *po, int optsum, mu_stream_t str)
optsum = 0;
}
else
mu_stream_printf (str, "[%s...]", _("OPTION"));
{
mu_stream_printf (str, "[%s...]", _("OPTION"));
if (po->po_special_args)
mu_stream_printf (str, " %s", gettext (po->po_special_args));
}
if (arg_text)
{
......
......@@ -578,6 +578,8 @@ parseopt_init (struct mu_parseopt *po, struct mu_option **options,
po->po_prog_doc = NULL;
if (!(flags & MU_PARSEOPT_PROG_ARGS))
po->po_prog_args = NULL;
if (!(flags & MU_PARSEOPT_SPECIAL_ARGS))
po->po_special_args = NULL;
if (!(flags & MU_PARSEOPT_BUG_ADDRESS))
po->po_bug_address = NULL;
if (!(flags & MU_PARSEOPT_PACKAGE_NAME))
......
......@@ -26,7 +26,6 @@ static char extra_doc[] = N_("Debug flags are:\n\
t - sieve trace (MU_SIEVE_DEBUG_TRACE)\n\
i - sieve instructions trace (MU_SIEVE_DEBUG_INSTR)\n\
l - sieve action logs");
static char args_doc[] = N_("[+FOLDER]");
static char *format_str = mh_list_format;
static int width = 80;
......@@ -345,7 +344,7 @@ main (int argc, char **argv)
size_t lastseen;
const char *unseen_seq;
mh_getopt (&argc, &argv, options, 0, args_doc, prog_doc, extra_doc);
mh_getopt (&argc, &argv, options, 0, NULL, prog_doc, extra_doc);
if (!append_folder)
append_folder = mh_global_profile_get ("Inbox", "inbox");
if (argc)
......
......@@ -135,7 +135,7 @@ mh_opt_set_folder (struct mu_parseopt *po, struct mu_option *opt,
}
static struct mu_option folder_option[] = {
{ "folder", 0, NULL, MU_OPTION_DEFAULT,
{ "folder", 0, N_("FOLDER"), MU_OPTION_DEFAULT,
N_("set current folder"),
mu_c_string, NULL, mh_opt_set_folder },
MU_OPTION_END
......@@ -164,6 +164,19 @@ There is NO WARRANTY, to the extent permitted by law.\n\
"));
}
static int
has_folder_option (struct mu_option *opt)
{
while (!MU_OPTION_IS_END (opt))
{
if (MU_OPTION_IS_VALID_LONG_OPTION (opt)
&& strcmp (opt->opt_long, "folder") == 0)
return 1;
++opt;
}
return 0;
}
void
mh_getopt (int *pargc, char ***pargv, struct mu_option *options,
int mhflags,
......@@ -184,6 +197,12 @@ mh_getopt (int *pargc, char ***pargv, struct mu_option *options,
po.po_negation = "no";
flags |= MU_PARSEOPT_NEGATION;
if ((mhflags & MH_GETOPT_DEFAULT_FOLDER) || has_folder_option (options))
{
po.po_special_args = N_("[+FOLDER]");
flags |= MU_PARSEOPT_SPECIAL_ARGS;
}
if (argdoc)
{
args[0] = argdoc;
......@@ -248,7 +267,12 @@ mh_getopt (int *pargc, char ***pargv, struct mu_option *options,
if (!argdoc && argc)
{
mu_error (_("Extra arguments"));
mu_diag_init ();
mu_stream_printf (mu_strerr, "\033s<%d>", MU_DIAG_ERROR);
mu_stream_printf (mu_strerr, "%s", _("unrecognized extra arguments:"));
for (i = 0; i < argc; i++)
mu_stream_printf (mu_strerr, " %s", argv[i]);
mu_stream_write (mu_strerr, "\n", 1, NULL);
exit (1);
}
......
......@@ -20,7 +20,7 @@
#include <mh.h>
static char prog_doc[] = N_("Print full pathnames of GNU MH messages and folders");
static char args_doc[] = N_("[+FOLDER] [MSGLIST]");
static char args_doc[] = N_("[MSGLIST]");
static int
mhpath (size_t num, mu_message_t msg, void *data)
......
......@@ -23,7 +23,7 @@
#include <unistd.h>
static char prog_doc[] = N_("Reply to a message");
static char args_doc[] = N_("[+FOLDER] [MESSAGE]");
static char args_doc[] = N_("[MESSAGE]");
static char *format_str = NULL;
static mh_format_t format;
......
......@@ -29,7 +29,6 @@
#include <dirent.h>
static char prog_doc[] = N_("Remove a GNU MH folder");
static char args_doc[] = N_("[+FOLDER]");
int explicit_folder; /* Was the folder explicitly given */
int interactive; /* Ask for confirmation before deleting */
......@@ -150,7 +149,7 @@ main (int argc, char **argv)
int status;
char *name;
mh_getopt (&argc, &argv, options, 0, args_doc, prog_doc, NULL);
mh_getopt (&argc, &argv, options, 0, NULL, prog_doc, NULL);
cur_folder_path = current_folder_path ();
......
......@@ -20,7 +20,7 @@
#include <mh.h>
static char prog_doc[] = N_("Remove messages");
static char args_doc[] = N_("[+FOLDER] [MSGLIST]");
static char args_doc[] = N_("[MSGLIST]");
static int
rmm (size_t num, mu_message_t msg, void *data)
......
......@@ -27,7 +27,7 @@
#include <mailutils/observer.h>
static char prog_doc[] = N_("Produce a one line per message scan listing");
static char args_doc[] = N_("[+FOLDER] [MSGLIST]");
static char args_doc[] = N_("[MSGLIST]");
static int clear;
static char *format_str = mh_list_format;
......
......@@ -20,7 +20,7 @@
#include <mh.h>
static char prog_doc[] = N_("Display GNU MH messages");
static char args_doc[] = N_("[+FOLDER] [MSGLIST]");
static char args_doc[] = N_("[MSGLIST]");
int use_draft;
int use_showproc = 1;
......