aboutsummaryrefslogtreecommitdiffstats
path: root/tests/t-argparse.c
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2020-02-27 11:32:01 +0000
committerWerner Koch <[email protected]>2020-02-27 13:33:45 +0000
commit2d1969ab465bad62f73a7c24ddc8bb490ff9fd40 (patch)
tree1abee93d70cd7ebbae54eb12512258dee5771430 /tests/t-argparse.c
parentindent: Fix indentation in an argparse.c function (diff)
downloadlibgpg-error-2d1969ab465bad62f73a7c24ddc8bb490ff9fd40.tar.gz
libgpg-error-2d1969ab465bad62f73a7c24ddc8bb490ff9fd40.zip
core: Implement meta commands for the argparser.
* src/argparse.c (opttable_t): Add new flags forced, ignore, and explicit_ignore. (struct _gpgrt_argparse_internal_s): Change flags to bitflags. Add several flags to support meta commands. (initialize): Clear them. (handle_meta_user): Use the new verbose flag. (handle_meta_force): Implement. (handle_meta_ignore): Implement. (handle_meta_echo): Support "-echo". (handle_meta_verbose): New. (handle_metacmd): New meta command verbose. Add always flag and move the detection of unexpected meta commands to here. (_gpgrt_argparse): Make use of the ignore and forced meta commands. (finish_read_sys): New. (_gpgrt_argparser): Support the verbose flag. Call finish_read_sys. (arg_parse): Ignore non-explicit ignored and all forced options. * tests/t-argparse.c (main): Fix printing of the ARGPARSE_CONFFILE case. New option 'M'. * tests/t-argparse.conf, tests/etc/t-argparse.conf: Various changes to test the new meta commands. -- For the command line we print a diagnostic if an ignored or forced options is used. However, we do not ignore options which are only set via [ignore-all]. The rationale for the latter is that an administrator can't be be required to unignore all options used by all modes, of say gpgme. Documentation of the meta commands will for now be added to GnuPG. GnuPG-bug-id: 4788 Signed-off-by: Werner Koch <[email protected]>
Diffstat (limited to 'tests/t-argparse.c')
-rw-r--r--tests/t-argparse.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/tests/t-argparse.c b/tests/t-argparse.c
index 4719819..46b7258 100644
--- a/tests/t-argparse.c
+++ b/tests/t-argparse.c
@@ -74,6 +74,7 @@ main (int argc, char **argv)
/* Note that on a non-utf8 terminal the ß might garble the output. */
ARGPARSE_s_n('s', "street","|Straße|set the name of the street to Straße"),
ARGPARSE_o_i('m', "my-option", 0),
+ ARGPARSE_o_i('M', "not-my-option", 0),
ARGPARSE_s_n(500, "a-long-option", 0 ),
ARGPARSE_conffile(501, "options", "|FILE|read options from FILE"),
ARGPARSE_noconffile(502, "no-options", "Ignore conf files"),
@@ -108,7 +109,7 @@ main (int argc, char **argv)
{
case ARGPARSE_CONFFILE:
printf ("current conffile='%s'\n",
- pargs.r.ret_str? pargs.r.ret_str: "[cmdline]");
+ pargs.r_type? pargs.r.ret_str: "[cmdline]");
break;
case ARGPARSE_IS_ARG :
printf ("arg='%s'\n", pargs.r.ret_str);
@@ -120,6 +121,7 @@ main (int argc, char **argv)
case 'o': opt.outfile = pargs.r.ret_str; break;
case 'c': opt.crf = pargs.r_type? pargs.r.ret_str:"a.crf"; break;
case 'm': opt.myopt = pargs.r_type? pargs.r.ret_int : 1; break;
+ case 'M': opt.myopt = 0; break;
case 500: opt.a_long_one++; break;
default : pargs.err = ARGPARSE_PRINT_WARNING; any_warn = 1; break;
}