6 #include "parse-options.h"
7 #include "string-list.h"
10 static const char * const builtin_column_usage
[] = {
11 N_("git column [<options>]"),
14 static unsigned int colopts
;
16 static int column_config(const char *var
, const char *value
, void *cb
)
18 return git_column_config(var
, value
, cb
, &colopts
);
21 int cmd_column(int argc
, const char **argv
, const char *prefix
)
23 struct string_list list
= STRING_LIST_INIT_DUP
;
24 struct strbuf sb
= STRBUF_INIT
;
25 struct column_options copts
;
26 const char *command
= NULL
, *real_command
= NULL
;
27 struct option options
[] = {
28 OPT_STRING(0, "command", &real_command
, N_("name"), N_("lookup config vars")),
29 OPT_COLUMN(0, "mode", &colopts
, N_("layout to use")),
30 OPT_INTEGER(0, "raw-mode", &colopts
, N_("layout to use")),
31 OPT_INTEGER(0, "width", &copts
.width
, N_("maximum width")),
32 OPT_STRING(0, "indent", &copts
.indent
, N_("string"), N_("padding space on left border")),
33 OPT_STRING(0, "nl", &copts
.nl
, N_("string"), N_("padding space on right border")),
34 OPT_INTEGER(0, "padding", &copts
.padding
, N_("padding space between columns")),
38 /* This one is special and must be the first one */
39 if (argc
> 1 && starts_with(argv
[1], "--command=")) {
40 command
= argv
[1] + 10;
41 git_config(column_config
, (void *)command
);
43 git_config(column_config
, NULL
);
45 memset(&copts
, 0, sizeof(copts
));
47 argc
= parse_options(argc
, argv
, prefix
, options
, builtin_column_usage
, 0);
49 usage_with_options(builtin_column_usage
, options
);
50 if (real_command
|| command
) {
51 if (!real_command
|| !command
|| strcmp(real_command
, command
))
52 die(_("--command must be the first argument"));
54 finalize_colopts(&colopts
, -1);
55 while (!strbuf_getline(&sb
, stdin
))
56 string_list_append(&list
, sb
.buf
);
58 print_columns(&list
, colopts
, &copts
);