builtin / column.con commit Merge branch 'jc/prune-all' (3e1e762)
   1#include "builtin.h"
   2#include "cache.h"
   3#include "strbuf.h"
   4#include "parse-options.h"
   5#include "string-list.h"
   6#include "column.h"
   7
   8static const char * const builtin_column_usage[] = {
   9        N_("git column [options]"),
  10        NULL
  11};
  12static unsigned int colopts;
  13
  14static int column_config(const char *var, const char *value, void *cb)
  15{
  16        return git_column_config(var, value, cb, &colopts);
  17}
  18
  19int cmd_column(int argc, const char **argv, const char *prefix)
  20{
  21        struct string_list list = STRING_LIST_INIT_DUP;
  22        struct strbuf sb = STRBUF_INIT;
  23        struct column_options copts;
  24        const char *command = NULL, *real_command = NULL;
  25        struct option options[] = {
  26                OPT_STRING(0, "command", &real_command, N_("name"), N_("lookup config vars")),
  27                OPT_COLUMN(0, "mode", &colopts, N_("layout to use")),
  28                OPT_INTEGER(0, "raw-mode", &colopts, N_("layout to use")),
  29                OPT_INTEGER(0, "width", &copts.width, N_("Maximum width")),
  30                OPT_STRING(0, "indent", &copts.indent, N_("string"), N_("Padding space on left border")),
  31                OPT_INTEGER(0, "nl", &copts.nl, N_("Padding space on right border")),
  32                OPT_INTEGER(0, "padding", &copts.padding, N_("Padding space between columns")),
  33                OPT_END()
  34        };
  35
  36        /* This one is special and must be the first one */
  37        if (argc > 1 && !prefixcmp(argv[1], "--command=")) {
  38                command = argv[1] + 10;
  39                git_config(column_config, (void *)command);
  40        } else
  41                git_config(column_config, NULL);
  42
  43        memset(&copts, 0, sizeof(copts));
  44        copts.width = term_columns();
  45        copts.padding = 1;
  46        argc = parse_options(argc, argv, "", options, builtin_column_usage, 0);
  47        if (argc)
  48                usage_with_options(builtin_column_usage, options);
  49        if (real_command || command) {
  50                if (!real_command || !command || strcmp(real_command, command))
  51                        die(_("--command must be the first argument"));
  52        }
  53        finalize_colopts(&colopts, -1);
  54        while (!strbuf_getline(&sb, stdin, '\n'))
  55                string_list_append(&list, sb.buf);
  56
  57        print_columns(&list, colopts, &copts);
  58        return 0;
  59}