aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2020-03-06 14:01:36 +0000
committerWerner Koch <[email protected]>2020-03-06 14:01:36 +0000
commit85b5006d01fc64763a6e1f0d6cbda91c5cb709c1 (patch)
tree47ad5c6fde7eed09d4cb0db69d1a87c432e3a608
parentcore: Add features for pretty printing the help (diff)
downloadlibgpg-error-85b5006d01fc64763a6e1f0d6cbda91c5cb709c1.tar.gz
libgpg-error-85b5006d01fc64763a6e1f0d6cbda91c5cb709c1.zip
core: Tweak the printing of headers in the --help output.
* src/argparse.c (show_help): Do not print empty sections between headers. Signed-off-by: Werner Koch <[email protected]>
-rw-r--r--NEWS2
-rw-r--r--src/argparse.c24
-rw-r--r--src/gpg-error.h.in3
3 files changed, 21 insertions, 8 deletions
diff --git a/NEWS b/NEWS
index 2f633e4..1deca6d 100644
--- a/NEWS
+++ b/NEWS
@@ -25,6 +25,8 @@ Noteworthy changes in version 1.38 (unreleased) [C28/A28/R_]
ARGPARSE_UNEXPECTED_META NEW.
ARGPARSE_conffile NEW.
ARGPARSE_noconffile NEW.
+ ARGPARSE_verbatim NEW.
+ ARGPARSE_header NEW.
GPGRT_CONFDIR_USER NEW.
GPGRT_CONFDIR_SYS NEW.
diff --git a/src/argparse.c b/src/argparse.c
index 0c42fa6..6b3488a 100644
--- a/src/argparse.c
+++ b/src/argparse.c
@@ -2200,7 +2200,8 @@ show_help (opttable_t *opts, unsigned int nopts, unsigned int flags)
if ( nopts )
{
/* Auto format the option description. */
- int i,j, indent;
+ int i,j,indent;
+ const char *last_header = NULL;
ordtbl = xtrycalloc (nopts, sizeof *ordtbl);
if (!ordtbl)
@@ -2238,14 +2239,23 @@ show_help (opttable_t *opts, unsigned int nopts, unsigned int flags)
s = map_fixed_string (_( opts[ordtbl[i]].description ));
if ( s && *s== '@' && !s[1] ) /* Hide this line. */
continue;
- if ( s && (opts[ordtbl[i]].flags
- & (ARGPARSE_OPT_VERBATIM|ARGPARSE_OPT_HEADER)))
+ if ( s && (opts[ordtbl[i]].flags & ARGPARSE_OPT_HEADER))
+ {
+ /* We delay printing until we have found one real output
+ * line. This avoids having a header above an empty
+ * section. */
+ last_header = s;
+ continue;
+ }
+ if (last_header)
+ {
+ if (*last_header)
+ writestrings (0, "\n", last_header, ":\n", NULL);
+ last_header = NULL;
+ }
+ if ( s && (opts[ordtbl[i]].flags & ARGPARSE_OPT_VERBATIM))
{
- 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. */
diff --git a/src/gpg-error.h.in b/src/gpg-error.h.in
index 9042a0f..e915797 100644
--- a/src/gpg-error.h.in
+++ b/src/gpg-error.h.in
@@ -1321,7 +1321,8 @@ typedef struct
{ 1, NULL, (ARGPARSE_OPT_VERBATIM), (d) }
/* Same as ARGPARSE_verbatim but also print a colon and a LF. N can
- * be used give a symbolic name to the header. */
+ * be used give a symbolic name to the header. Nothing is printed if
+ * D is the empty string. */
#define ARGPARSE_header(n,d) \
{ 1, (n), (ARGPARSE_OPT_HEADER), (d) }