]> git.ipfire.org Git - thirdparty/git.git/blobdiff - git.c
git.c: convert --list-* to --list-cmds=*
[thirdparty/git.git] / git.c
diff --git a/git.c b/git.c
index 3a89893712e6b327e714ad81d12d3e4ca354926c..cd85355d8114beb4d34211a4bae8afa04dc04a5b 100644 (file)
--- a/git.c
+++ b/git.c
@@ -38,6 +38,30 @@ static int use_pager = -1;
 
 static void list_builtins(unsigned int exclude_option, char sep);
 
+static int match_token(const char *spec, int len, const char *token)
+{
+       int token_len = strlen(token);
+
+       return len == token_len && !strncmp(spec, token, token_len);
+}
+
+static int list_cmds(const char *spec)
+{
+       while (*spec) {
+               const char *sep = strchrnul(spec, ',');
+               int len = sep - spec;
+
+               if (match_token(spec, len, "builtins"))
+                       list_builtins(0, '\n');
+               else
+                       die(_("unsupported command listing type '%s'"), spec);
+               spec += len;
+               if (*spec == ',')
+                       spec++;
+       }
+       return 0;
+}
+
 static void commit_pager_choice(void) {
        switch (use_pager) {
        case 0:
@@ -223,12 +247,13 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)
                        }
                        (*argv)++;
                        (*argc)--;
-               } else if (!strcmp(cmd, "--list-builtins")) {
-                       list_builtins(0, '\n');
-                       exit(0);
-               } else if (!strcmp(cmd, "--list-parseopt-builtins")) {
-                       list_builtins(NO_PARSEOPT, ' ');
-                       exit(0);
+               } else if (skip_prefix(cmd, "--list-cmds=", &cmd)) {
+                       if (!strcmp(cmd, "parseopt")) {
+                               list_builtins(NO_PARSEOPT, ' ');
+                               exit(0);
+                       } else {
+                               exit(list_cmds(cmd));
+                       }
                } else {
                        fprintf(stderr, _("unknown option: %s\n"), cmd);
                        usage(git_usage_string);