summaryrefslogtreecommitdiff
path: root/parse-options.h
diff options
context:
space:
mode:
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>2019-01-27 00:35:23 (GMT)
committerJunio C Hamano <gitster@pobox.com>2019-01-28 00:28:17 (GMT)
commit202fbb33156287feeabc39c46db0e9857cb97152 (patch)
treef609f6fb79e2386f788be51286347bd8339849e3 /parse-options.h
parent1987b0b20f7b29a25260fd25f907121d22b18b32 (diff)
downloadgit-202fbb33156287feeabc39c46db0e9857cb97152.zip
git-202fbb33156287feeabc39c46db0e9857cb97152.tar.gz
git-202fbb33156287feeabc39c46db0e9857cb97152.tar.bz2
parse-options: add one-shot mode
This is to help reimplement diff_opt_parse() using parse_options(). The behavior of parse_options() is changed to be the same as the other: - no argv0 in argv[], everything can be processed - argv[] must not be updated, it's the caller's job to do that - return the number of arguments processed - leave all unknown options / non-options alone (this one can already be achieved with PARSE_OPT_KEEP_UNKNOWN and PARSE_OPT_STOP_AT_NON_OPTION) This mode is NOT supposed to stay here for long. It's to help converting diff/rev option parsing. Once that work is over and we can just use parse_options() throughout the code base, this will be deleted. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'parse-options.h')
-rw-r--r--parse-options.h17
1 files changed, 13 insertions, 4 deletions
diff --git a/parse-options.h b/parse-options.h
index f5e7ec7..d663b83 100644
--- a/parse-options.h
+++ b/parse-options.h
@@ -27,7 +27,8 @@ enum parse_opt_flags {
PARSE_OPT_STOP_AT_NON_OPTION = 2,
PARSE_OPT_KEEP_ARGV0 = 4,
PARSE_OPT_KEEP_UNKNOWN = 8,
- PARSE_OPT_NO_INTERNAL_HELP = 16
+ PARSE_OPT_NO_INTERNAL_HELP = 16,
+ PARSE_OPT_ONE_SHOT = 32
};
enum parse_opt_option_flags {
@@ -169,10 +170,18 @@ struct option {
N_("no-op (backward compatibility)"), \
PARSE_OPT_HIDDEN | PARSE_OPT_NOARG, parse_opt_noop_cb }
-/* parse_options() will filter out the processed options and leave the
- * non-option arguments in argv[]. usagestr strings should be marked
- * for translation with N_().
+/*
+ * parse_options() will filter out the processed options and leave the
+ * non-option arguments in argv[]. argv0 is assumed program name and
+ * skipped.
+ *
+ * usagestr strings should be marked for translation with N_().
+ *
* Returns the number of arguments left in argv[].
+ *
+ * In one-shot mode, argv0 is not a program name, argv[] is left
+ * untouched and parse_options() returns the number of options
+ * processed.
*/
int parse_options(int argc, const char **argv, const char *prefix,
const struct option *options,