]>
Commit | Line | Data |
---|---|---|
7e29b825 | 1 | #include "builtin.h" |
b2141fc1 | 2 | #include "config.h" |
f394e093 | 3 | #include "gettext.h" |
7e29b825 NTND |
4 | #include "strbuf.h" |
5 | #include "parse-options.h" | |
6 | #include "string-list.h" | |
7 | #include "column.h" | |
8 | ||
9 | static const char * const builtin_column_usage[] = { | |
9c9b4f2f | 10 | N_("git column [<options>]"), |
7e29b825 NTND |
11 | NULL |
12 | }; | |
13 | static unsigned int colopts; | |
14 | ||
a4e7e317 GC |
15 | static int column_config(const char *var, const char *value, |
16 | const struct config_context *ctx UNUSED, void *cb) | |
7e29b825 NTND |
17 | { |
18 | return git_column_config(var, value, cb, &colopts); | |
19 | } | |
20 | ||
21 | int cmd_column(int argc, const char **argv, const char *prefix) | |
22 | { | |
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[] = { | |
997f44d0 NTND |
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")), | |
5ee90326 CC |
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")), | |
c93ca46c | 33 | OPT_STRING(0, "nl", &copts.nl, N_("string"), N_("padding space on right border")), |
5ee90326 | 34 | OPT_INTEGER(0, "padding", &copts.padding, N_("padding space between columns")), |
7e29b825 NTND |
35 | OPT_END() |
36 | }; | |
37 | ||
38 | /* This one is special and must be the first one */ | |
59556548 | 39 | if (argc > 1 && starts_with(argv[1], "--command=")) { |
7e29b825 NTND |
40 | command = argv[1] + 10; |
41 | git_config(column_config, (void *)command); | |
42 | } else | |
43 | git_config(column_config, NULL); | |
44 | ||
45 | memset(&copts, 0, sizeof(copts)); | |
7e29b825 | 46 | copts.padding = 1; |
d64db5b3 | 47 | argc = parse_options(argc, argv, prefix, options, builtin_column_usage, 0); |
f2d31c69 KH |
48 | if (copts.padding < 0) |
49 | die(_("%s must be non-negative"), "--padding"); | |
7e29b825 NTND |
50 | if (argc) |
51 | usage_with_options(builtin_column_usage, options); | |
52 | if (real_command || command) { | |
53 | if (!real_command || !command || strcmp(real_command, command)) | |
54 | die(_("--command must be the first argument")); | |
55 | } | |
56 | finalize_colopts(&colopts, -1); | |
1536dd9c | 57 | while (!strbuf_getline(&sb, stdin)) |
7e29b825 NTND |
58 | string_list_append(&list, sb.buf); |
59 | ||
60 | print_columns(&list, colopts, &copts); | |
cd3c28c5 RS |
61 | strbuf_release(&sb); |
62 | string_list_clear(&list, 0); | |
7e29b825 NTND |
63 | return 0; |
64 | } |