MCPcopy Index your code
hub / github.com/git/git / parse_options

Function parse_options

parse-options.c:1181–1235  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1179}
1180
1181int parse_options(int argc, const char **argv,
1182 const char *prefix,
1183 const struct option *options,
1184 const char * const usagestr[],
1185 enum parse_opt_flags flags)
1186{
1187 struct parse_opt_ctx_t ctx;
1188 struct option *real_options;
1189
1190 disallow_abbreviated_options =
1191 git_env_bool("GIT_TEST_DISALLOW_ABBREVIATED_OPTIONS", 0);
1192
1193 memset(&ctx, 0, sizeof(ctx));
1194 real_options = preprocess_options(&ctx, options);
1195 if (real_options)
1196 options = real_options;
1197 parse_options_start_1(&ctx, argc, argv, prefix, options, flags);
1198 switch (parse_options_step(&ctx, options, usagestr)) {
1199 case PARSE_OPT_HELP:
1200 case PARSE_OPT_ERROR:
1201 exit(129);
1202 case PARSE_OPT_COMPLETE:
1203 exit(0);
1204 case PARSE_OPT_NON_OPTION:
1205 case PARSE_OPT_SUBCOMMAND:
1206 break;
1207 case PARSE_OPT_DONE:
1208 if (ctx.has_subcommands &&
1209 !(flags & PARSE_OPT_SUBCOMMAND_OPTIONAL)) {
1210 error(_("need a subcommand"));
1211 usage_with_options(usagestr, options);
1212 }
1213 break;
1214 case PARSE_OPT_UNKNOWN:
1215 if (ctx.argv[0][1] == '-') {
1216 error(_("unknown option `%s'"), ctx.argv[0] + 2);
1217 } else if (isascii(*ctx.opt)) {
1218 error(_("unknown switch `%c'"), *ctx.opt);
1219 } else {
1220 error(_("unknown non-ascii option in string: `%s'"),
1221 ctx.argv[0]);
1222 }
1223 usage_with_options(usagestr, options);
1224 }
1225
1226 precompose_argv_prefix(argc, argv, NULL);
1227 free_preprocessed_options(real_options);
1228 free(ctx.alias_groups);
1229 for (struct parse_opt_cmdmode_list *elem = ctx.cmdmode_list; elem;) {
1230 struct parse_opt_cmdmode_list *next = elem->next;
1231 free(elem);
1232 elem = next;
1233 }
1234 return parse_options_end(&ctx);
1235}
1236
1237static int usage_argh(const struct option *opts, FILE *outfile)
1238{

Callers 15

cmd_versionFunction · 0.85
pack_refs_coreFunction · 0.85
parse_archive_argsFunction · 0.85
diff_no_indexFunction · 0.85
apply_parse_optionsFunction · 0.85
cmd_cloneFunction · 0.85
cmd_diagnoseFunction · 0.85
cmd_registerFunction · 0.85
cmd_reconfigureFunction · 0.85
cmd_runFunction · 0.85
cmd_unregisterFunction · 0.85
cmd_deleteFunction · 0.85

Calls 9

git_env_boolFunction · 0.85
preprocess_optionsFunction · 0.85
parse_options_start_1Function · 0.85
parse_options_stepFunction · 0.85
errorFunction · 0.85
usage_with_optionsFunction · 0.85
parse_options_endFunction · 0.85
precompose_argv_prefixFunction · 0.70

Tested by 15

cmd_mainFunction · 0.68
cmd__simple_ipcFunction · 0.68
cmd__progressFunction · 0.68
unpack_sidebandFunction · 0.68
cmd__parse_optionsFunction · 0.68
parse_options_flags__cmdFunction · 0.68
cmd__parse_options_flagsFunction · 0.68
parse_subcommand__cmdFunction · 0.68
cmd__parse_subcommandFunction · 0.68
cmd__fsmonitor_clientFunction · 0.68
cmd__cache_treeFunction · 0.68
cmd__lazy_init_name_hashFunction · 0.68