#include "exec_cmd.h"
#include "help.h"
#include "run-command.h"
+#include "alias.h"
#define RUN_SETUP (1<<0)
#define RUN_SETUP_GENTLY (1<<1)
static int use_pager = -1;
-static void list_builtins(unsigned int exclude_option, char sep);
+static void list_builtins(struct string_list *list, unsigned int exclude_option);
static int match_token(const char *spec, int len, const char *token)
{
static int list_cmds(const char *spec)
{
+ struct string_list list = STRING_LIST_INIT_DUP;
+ int i;
+
while (*spec) {
const char *sep = strchrnul(spec, ',');
int len = sep - spec;
if (match_token(spec, len, "builtins"))
- list_builtins(0, '\n');
+ list_builtins(&list, 0);
+ else if (match_token(spec, len, "main"))
+ list_all_main_cmds(&list);
+ else if (match_token(spec, len, "others"))
+ list_all_other_cmds(&list);
+ else if (len > 5 && !strncmp(spec, "list-", 5)) {
+ struct strbuf sb = STRBUF_INIT;
+
+ strbuf_add(&sb, spec + 5, len - 5);
+ list_cmds_by_category(&list, sb.buf);
+ strbuf_release(&sb);
+ }
else
die(_("unsupported command listing type '%s'"), spec);
spec += len;
if (*spec == ',')
spec++;
}
+ for (i = 0; i < list.nr; i++)
+ puts(list.items[i].string);
+ string_list_clear(&list, 0);
return 0;
}
(*argc)--;
} else if (skip_prefix(cmd, "--list-cmds=", &cmd)) {
if (!strcmp(cmd, "parseopt")) {
- list_builtins(NO_PARSEOPT, ' ');
+ struct string_list list = STRING_LIST_INIT_DUP;
+ int i;
+
+ list_builtins(&list, NO_PARSEOPT);
+ for (i = 0; i < list.nr; i++)
+ printf("%s ", list.items[i].string);
+ string_list_clear(&list, 0);
exit(0);
} else {
exit(list_cmds(cmd));
return !!get_builtin(s);
}
-static void list_builtins(unsigned int exclude_option, char sep)
+static void list_builtins(struct string_list *out, unsigned int exclude_option)
{
int i;
for (i = 0; i < ARRAY_SIZE(commands); i++) {
if (exclude_option &&
(commands[i].option & exclude_option))
continue;
- printf("%s%c", commands[i].cmd, sep);
+ string_list_append(out, commands[i].cmd);
}
}