From: Junio C Hamano Date: Mon, 11 Nov 2019 02:34:26 GMT Subject: Re: [PATCH v3 1/3] bundle: framework for options before bundle file Message-ID: In-Reply-To: <20191110204126.30553-1-robbat2@gentoo.org> "Robin H. Johnson" writes: > +static int verbose; > + > +static int parse_options_cmd_bundle(int argc, > + const char **argv, > + const char* prefix, > + const char * const usagestr[], > + const struct option options[], > + const char **bundle_file) { > + int newargc; > + newargc = parse_options(argc, argv, NULL, options, usagestr, > + PARSE_OPT_STOP_AT_NON_OPTION); > + if (argc < 1) > + usage_with_options(usagestr, options); > + *bundle_file = prefix_filename(prefix, argv[0]); > + return newargc; > +} Looks like a useful helper to be shared among subcommands. > +static int cmd_bundle_create(int argc, const char **argv, const char *prefix) { > + struct option options[] = { > + OPT_END() > + }; > + const char* bundle_file; > ... > +int cmd_bundle(int argc, const char **argv, const char *prefix) > +{ > + struct option options[] = { > + OPT__VERBOSE(&verbose, N_("be verbose; must be placed before a subcommand")), > + OPT_END() > + }; > + int result; > + > + argc = parse_options(argc, argv, prefix, options, builtin_bundle_usage, > + PARSE_OPT_STOP_AT_NON_OPTION); Looks like a reasonable arrangement for two-level option parser.