examples: keep track of whether we processed a "--" arg

parent 025a9357
...@@ -168,3 +168,16 @@ int match_int_arg( ...@@ -168,3 +168,16 @@ int match_int_arg(
return 0; return 0;
return match_int_internal(out, found, allow_negative, opt); return match_int_internal(out, found, allow_negative, opt);
} }
int match_arg_separator(struct args_info *args)
{
if (args->opts_done)
return 1;
if (strcmp(args->argv[args->pos], "--") != 0)
return 0;
args->opts_done = 1;
args->pos++;
return 1;
}
...@@ -8,6 +8,7 @@ struct args_info { ...@@ -8,6 +8,7 @@ struct args_info {
int argc; int argc;
char **argv; char **argv;
int pos; int pos;
int opts_done : 1; /**< Did we see a -- separator */
}; };
#define ARGS_INFO_INIT { argc, argv, 0, 0 } #define ARGS_INFO_INIT { argc, argv, 0, 0 }
#define ARGS_CURRENT(args) args->argv[args->pos] #define ARGS_CURRENT(args) args->argv[args->pos]
...@@ -76,4 +77,9 @@ extern int match_int_arg( ...@@ -76,4 +77,9 @@ extern int match_int_arg(
*/ */
extern int match_bool_arg(int *out, struct args_info *args, const char *opt); extern int match_bool_arg(int *out, struct args_info *args, const char *opt);
/**
* Check if we're processing past the single -- separator
*/
extern int match_arg_separator(struct args_info *args);
#endif #endif
...@@ -65,7 +65,7 @@ static void parse_options(const char **repo_path, checkout_options *opts, struct ...@@ -65,7 +65,7 @@ static void parse_options(const char **repo_path, checkout_options *opts, struct
const char *curr = args->argv[args->pos]; const char *curr = args->argv[args->pos];
int bool_arg; int bool_arg;
if (strcmp(curr, "--") == 0) { if (match_arg_separator(args)) {
break; break;
} else if (!strcmp(curr, "--force")) { } else if (!strcmp(curr, "--force")) {
opts->force = 1; opts->force = 1;
...@@ -190,11 +190,7 @@ int lg2_checkout(git_repository *repo, int argc, char **argv) ...@@ -190,11 +190,7 @@ int lg2_checkout(git_repository *repo, int argc, char **argv)
goto cleanup; goto cleanup;
} }
if (args.pos >= args.argc) { if (match_arg_separator(&args)) {
fprintf(stderr, "unhandled\n");
err = -1;
goto cleanup;
} else if (!strcmp("--", args.argv[args.pos])) {
/** /**
* Try to checkout the given path * Try to checkout the given path
*/ */
......
...@@ -84,8 +84,7 @@ int main(int argc, char **argv) ...@@ -84,8 +84,7 @@ int main(int argc, char **argv)
break; break;
} else if (optional_str_arg(&git_dir, &args, "--git-dir", ".git")) { } else if (optional_str_arg(&git_dir, &args, "--git-dir", ".git")) {
continue; continue;
} else if (!strcmp(a, "--")) { } else if (match_arg_separator(&args)) {
/* arg separator */
break; break;
} }
} }
......
...@@ -424,8 +424,7 @@ static int parse_options( ...@@ -424,8 +424,7 @@ static int parse_options(
else else
/** Try failed revision parse as filename. */ /** Try failed revision parse as filename. */
break; break;
} else if (!strcmp(a, "--")) { } else if (!match_arg_separator(&args)) {
++args.pos;
break; break;
} }
else if (!strcmp(a, "--date-order")) else if (!strcmp(a, "--date-order"))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment