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