Git fork
at reftables-rust 68 lines 2.2 kB view raw
1#define USE_THE_REPOSITORY_VARIABLE 2#include "builtin.h" 3#include "config.h" 4#include "gettext.h" 5#include "strbuf.h" 6#include "parse-options.h" 7#include "string-list.h" 8#include "column.h" 9 10static const char * const builtin_column_usage[] = { 11 N_("git column [<options>]"), 12 NULL 13}; 14static unsigned int colopts; 15 16static int column_config(const char *var, const char *value, 17 const struct config_context *ctx UNUSED, void *cb) 18{ 19 return git_column_config(var, value, cb, &colopts); 20} 21 22int cmd_column(int argc, 23 const char **argv, 24 const char *prefix, 25 struct repository *repo UNUSED) 26{ 27 struct string_list list = STRING_LIST_INIT_DUP; 28 struct strbuf sb = STRBUF_INIT; 29 struct column_options copts; 30 const char *command = NULL, *real_command = NULL; 31 struct option options[] = { 32 OPT_STRING(0, "command", &real_command, N_("name"), N_("lookup config vars")), 33 OPT_COLUMN(0, "mode", &colopts, N_("layout to use")), 34 OPT_UNSIGNED(0, "raw-mode", &colopts, N_("layout to use")), 35 OPT_INTEGER(0, "width", &copts.width, N_("maximum width")), 36 OPT_STRING(0, "indent", &copts.indent, N_("string"), N_("padding space on left border")), 37 OPT_STRING(0, "nl", &copts.nl, N_("string"), N_("padding space on right border")), 38 OPT_INTEGER(0, "padding", &copts.padding, N_("padding space between columns")), 39 OPT_END() 40 }; 41 42 /* This one is special and must be the first one */ 43 if (argc > 1 && starts_with(argv[1], "--command=")) { 44 command = argv[1] + 10; 45 repo_config(the_repository, column_config, (void *)command); 46 } else 47 repo_config(the_repository, column_config, NULL); 48 49 memset(&copts, 0, sizeof(copts)); 50 copts.padding = 1; 51 argc = parse_options(argc, argv, prefix, options, builtin_column_usage, 0); 52 if (copts.padding < 0) 53 die(_("%s must be non-negative"), "--padding"); 54 if (argc) 55 usage_with_options(builtin_column_usage, options); 56 if (real_command || command) { 57 if (!real_command || !command || strcmp(real_command, command)) 58 die(_("--command must be the first argument")); 59 } 60 finalize_colopts(&colopts, -1); 61 while (!strbuf_getline(&sb, stdin)) 62 string_list_append(&list, sb.buf); 63 64 print_columns(&list, colopts, &copts); 65 strbuf_release(&sb); 66 string_list_clear(&list, 0); 67 return 0; 68}