aboutsummaryrefslogtreecommitdiffstats
path: root/src/argparse.c
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2020-03-06 10:10:36 +0000
committerWerner Koch <[email protected]>2020-03-06 10:10:36 +0000
commitc59bf5824aafe938d5ab0d69079b9d93debc19fe (patch)
treec0a69785a6faac36201769a977873b6f701630c3 /src/argparse.c
parentcore: New function gpgrt_reallocarray. (diff)
downloadlibgpg-error-c59bf5824aafe938d5ab0d69079b9d93debc19fe.tar.gz
libgpg-error-c59bf5824aafe938d5ab0d69079b9d93debc19fe.zip
core: Add features for pretty printing the help
* src/gpg-error.h.in (ARGPARSE_OPT_HEADER): New. (ARGPARSE_OPT_VERBATIM): New. (ARGPARSE_verbatim): New. (ARGPARSE_header): New. * src/argparse.c (show_help): Implement them. -- These two macros are useful for custom help screens. In contrast to the ARGPARSE_group hack they do not need a short option number (we use 1 here as a surrogate) and not the "@" hack. Thus already translated strings can be used. ARGPARSE_header further allows to specify a symbolic name for the group and does some minor formatting. If such a symbolic name is given --dump-option-table also emits this as a pseudo option for consumption by GUIs which for example use tabs to group options. Signed-off-by: Werner Koch <[email protected]>
Diffstat (limited to '')
-rw-r--r--src/argparse.c21
1 files changed, 17 insertions, 4 deletions
diff --git a/src/argparse.c b/src/argparse.c
index 223d267..0c42fa6 100644
--- a/src/argparse.c
+++ b/src/argparse.c
@@ -2171,9 +2171,10 @@ cmp_ordtbl (const void *a_v, const void *b_v)
* meanings:
* - A description string which is "@" suppresses help output for
* this option
- * - a description,ine which starts with a '@' and is followed by
+ * - a description which starts with a '@' and is followed by
* any other characters is printed as is; this may be used for examples
- * ans such.
+ * and such. This is a legacy methiod, moder codes uses the flags
+ * ARGPARSE_OPT_VERBATIM or ARGPARSE_OPT_HEADER.
* - A description which starts with a '|' outputs the string between this
* bar and the next one as arguments of the long option.
*/
@@ -2228,14 +2229,26 @@ show_help (opttable_t *opts, unsigned int nopts, unsigned int flags)
/* Example: " -v, --verbose Viele Sachen ausgeben" */
indent += 10;
- if ( *opts[ordtbl[0]].description != '@' )
+ if ( *opts[ordtbl[0]].description != '@'
+ && !(opts[ordtbl[0]].flags
+ & (ARGPARSE_OPT_VERBATIM|ARGPARSE_OPT_HEADER)))
writestrings (0, "Options:", "\n", NULL);
for (i=0; i < nopts; i++ )
{
s = map_fixed_string (_( opts[ordtbl[i]].description ));
if ( s && *s== '@' && !s[1] ) /* Hide this line. */
continue;
- if ( s && *s == '@' ) /* Unindented comment only line. */
+ if ( s && (opts[ordtbl[i]].flags
+ & (ARGPARSE_OPT_VERBATIM|ARGPARSE_OPT_HEADER)))
+ {
+ if ((opts[ordtbl[i]].flags & ARGPARSE_OPT_HEADER))
+ writestrings (0, "\n", NULL);
+ writestrings (0, s, NULL);
+ if ((opts[ordtbl[i]].flags & ARGPARSE_OPT_HEADER))
+ writestrings (0, ":\n", NULL);
+ continue;
+ }
+ if ( s && *s == '@' ) /* Unindented legacy comment only line. */
{
for (s++; *s; s++ )
{