summaryrefslogtreecommitdiffstats
path: root/src/hook.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/hook.c')
-rw-r--r--src/hook.c42
1 files changed, 30 insertions, 12 deletions
diff --git a/src/hook.c b/src/hook.c
index ddce87d..b7d12a5 100644
--- a/src/hook.c
+++ b/src/hook.c
@@ -225,14 +225,28 @@ static const char *identity(hook_opts o)
return NULL;
}
-static int flag(const char *arg, const char *name, const char **slot)
+// "--ff=yes" and "--ff yes" mean the same thing. The usage text writes the
+// two-word form and validate accepts both, so authorize accepts both: an option
+// the help offers must not come back as "unknown argument".
+
+static int option(int argc, char **argv, int *i, const char *name,
+ const char **slot)
{
size_t n = strlen(name);
- if (strncmp(arg, name, n) != 0 || arg[n] != '=')
- return 0;
- *slot = arg + n + 1;
- return 1;
+ if (strcmp(argv[*i], name) == 0) {
+ if (*i + 1 >= argc) {
+ fprintf(stderr, "%s: %s wants a value\n", progname, name);
+ return -1;
+ }
+ *slot = argv[++*i];
+ return 1;
+ }
+ if (strncmp(argv[*i], name, n) == 0 && argv[*i][n] == '=') {
+ *slot = argv[*i] + n + 1;
+ return 1;
+ }
+ return 0;
}
int cmd_authorize(const policy_t *p, hook_opts o, int argc, char **argv)
@@ -253,13 +267,17 @@ int cmd_authorize(const policy_t *p, hook_opts o, int argc, char **argv)
o.head = "auto";
for (i = 0; i < argc; i++) {
- if (flag(argv[i], "--user", &o.user))
- continue;
- if (flag(argv[i], "--repo", &o.repo))
- continue;
- if (flag(argv[i], "--ff", &o.ff))
- continue;
- if (flag(argv[i], "--head", &o.head))
+ int got = option(argc, argv, &i, "--user", &o.user);
+
+ if (got == 0)
+ got = option(argc, argv, &i, "--repo", &o.repo);
+ if (got == 0)
+ got = option(argc, argv, &i, "--ff", &o.ff);
+ if (got == 0)
+ got = option(argc, argv, &i, "--head", &o.head);
+ if (got < 0)
+ return 64;
+ if (got > 0)
continue;
if (strcmp(argv[i], "--no-git") == 0) {
o.use_git = 0;