From 9ef47a43a4127c16df468ee24f488358073dfa2c Mon Sep 17 00:00:00 2001 From: Kurtis Rader Date: Thu, 20 Jul 2017 17:54:06 -0700 Subject: [PATCH] change how `argparse` handles boolean flags When reporting whether a boolean flag was seen report the actual flags rather than a summary count. For example, if you have option spec `h/help` and we parse `-h --help -h` don't do the equivalent of `set _flag_h 3` do `set _flag_h -h --help -h`. Partial fix for #4226 --- doc_src/argparse.txt | 2 +- src/builtin_argparse.cpp | 8 ++++++++ tests/argparse.out | 16 ++++++++-------- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/doc_src/argparse.txt b/doc_src/argparse.txt index ae763382d..fc95946e0 100644 --- a/doc_src/argparse.txt +++ b/doc_src/argparse.txt @@ -13,7 +13,7 @@ Each OPTION_SPEC can be written in the domain specific language long_flag); + } assert(!w.woptarg); long_idx = -1; continue; diff --git a/tests/argparse.out b/tests/argparse.out index 71df1f721..eb3752ec8 100644 --- a/tests/argparse.out +++ b/tests/argparse.out @@ -2,8 +2,8 @@ # One arg and no matching flags argv help # Five args with two matching a flag -_flag_h 2 -_flag_help 2 +_flag_h '--help' '-h' +_flag_help '--help' '-h' argv 'help' 'me' 'a lot more' # Required, optional, and multiple flags _flag_a ABC @@ -12,23 +12,23 @@ _flag_d _flag_def _flag_g 'g1' 'g2' 'g3' _flag_ghk 'g1' 'g2' 'g3' -_flag_h 1 -_flag_help 1 +_flag_h --help +_flag_help --help argv 'help' 'me' # --stop-nonopt works _flag_a A2 _flag_abc A2 -_flag_h 1 -_flag_help 1 +_flag_h -h +_flag_help -h argv 'non-opt' 'second non-opt' '--help' # Implicit int flags work _flag_val 123 argv 'abc' 'def' _flag_t woohoo _flag_token woohoo -_flag_v 2 +_flag_v '-v' '--verbose' _flag_val -234 -_flag_verbose 2 +_flag_verbose '-v' '--verbose' argv 'a1' 'a2' # Should be set to 987 _flag_m 987