| 993 | int usage_to_stderr); |
| 994 | |
| 995 | enum parse_opt_result parse_options_step(struct parse_opt_ctx_t *ctx, |
| 996 | const struct option *options, |
| 997 | const char * const usagestr[]) |
| 998 | { |
| 999 | int internal_help = !(ctx->flags & PARSE_OPT_NO_INTERNAL_HELP); |
| 1000 | |
| 1001 | /* we must reset ->opt, unknown short option leave it dangling */ |
| 1002 | ctx->opt = NULL; |
| 1003 | |
| 1004 | for (; ctx->argc; ctx->argc--, ctx->argv++) { |
| 1005 | const char *arg = ctx->argv[0]; |
| 1006 | |
| 1007 | if (ctx->flags & PARSE_OPT_ONE_SHOT && |
| 1008 | ctx->argc != ctx->total) |
| 1009 | break; |
| 1010 | |
| 1011 | if (*arg != '-' || !arg[1]) { |
| 1012 | if (parse_nodash_opt(ctx, arg, options) == 0) |
| 1013 | continue; |
| 1014 | if (!ctx->has_subcommands) { |
| 1015 | if (ctx->flags & PARSE_OPT_STOP_AT_NON_OPTION) |
| 1016 | return PARSE_OPT_NON_OPTION; |
| 1017 | ctx->out[ctx->cpidx++] = ctx->argv[0]; |
| 1018 | continue; |
| 1019 | } |
| 1020 | switch (parse_subcommand(arg, options)) { |
| 1021 | case PARSE_OPT_SUBCOMMAND: |
| 1022 | return PARSE_OPT_SUBCOMMAND; |
| 1023 | case PARSE_OPT_UNKNOWN: |
| 1024 | if (ctx->flags & PARSE_OPT_SUBCOMMAND_OPTIONAL) |
| 1025 | /* |
| 1026 | * arg is neither a short or long |
| 1027 | * option nor a subcommand. Since |
| 1028 | * this command has a default |
| 1029 | * operation mode, we have to treat |
| 1030 | * this arg and all remaining args |
| 1031 | * as args meant to that default |
| 1032 | * operation mode. |
| 1033 | * So we are done parsing. |
| 1034 | */ |
| 1035 | return PARSE_OPT_DONE; |
| 1036 | error(_("unknown subcommand: `%s'"), arg); |
| 1037 | usage_with_options(usagestr, options); |
| 1038 | case PARSE_OPT_COMPLETE: |
| 1039 | case PARSE_OPT_HELP: |
| 1040 | case PARSE_OPT_ERROR: |
| 1041 | case PARSE_OPT_DONE: |
| 1042 | case PARSE_OPT_NON_OPTION: |
| 1043 | /* Impossible. */ |
| 1044 | BUG("parse_subcommand() cannot return these"); |
| 1045 | } |
| 1046 | } |
| 1047 | |
| 1048 | /* lone -h asks for help */ |
| 1049 | if (internal_help && ctx->total == 1 && !strcmp(arg + 1, "h")) |
| 1050 | goto show_usage; |
| 1051 | |
| 1052 | /* |
no test coverage detected