|
| 1 | +#define USE_THE_REPOSITORY_VARIABLE |
| 2 | + |
| 3 | +#include "builtin.h" |
| 4 | +#include "config.h" |
| 5 | +#include "parse-options.h" |
| 6 | + |
| 7 | +static const char * const survey_usage[] = { |
| 8 | + N_("(EXPERIMENTAL!) git survey <options>"), |
| 9 | + NULL, |
| 10 | +}; |
| 11 | + |
| 12 | +struct survey_opts { |
| 13 | + int verbose; |
| 14 | + int show_progress; |
| 15 | +}; |
| 16 | + |
| 17 | +struct survey_context { |
| 18 | + struct repository *repo; |
| 19 | + |
| 20 | + /* Options that control what is done. */ |
| 21 | + struct survey_opts opts; |
| 22 | +}; |
| 23 | + |
| 24 | +static int survey_load_config_cb(const char *var, const char *value, |
| 25 | + const struct config_context *cctx, void *pvoid) |
| 26 | +{ |
| 27 | + struct survey_context *ctx = pvoid; |
| 28 | + |
| 29 | + if (!strcmp(var, "survey.verbose")) { |
| 30 | + ctx->opts.verbose = git_config_bool(var, value); |
| 31 | + return 0; |
| 32 | + } |
| 33 | + if (!strcmp(var, "survey.progress")) { |
| 34 | + ctx->opts.show_progress = git_config_bool(var, value); |
| 35 | + return 0; |
| 36 | + } |
| 37 | + |
| 38 | + return git_default_config(var, value, cctx, pvoid); |
| 39 | +} |
| 40 | + |
| 41 | +static void survey_load_config(struct survey_context *ctx) |
| 42 | +{ |
| 43 | + git_config(survey_load_config_cb, ctx); |
| 44 | +} |
| 45 | + |
| 46 | +int cmd_survey(int argc, const char **argv, const char *prefix, struct repository *repo) |
| 47 | +{ |
| 48 | + static struct survey_context ctx = { |
| 49 | + .opts = { |
| 50 | + .verbose = 0, |
| 51 | + .show_progress = -1, /* defaults to isatty(2) */ |
| 52 | + }, |
| 53 | + }; |
| 54 | + |
| 55 | + static struct option survey_options[] = { |
| 56 | + OPT__VERBOSE(&ctx.opts.verbose, N_("verbose output")), |
| 57 | + OPT_BOOL(0, "progress", &ctx.opts.show_progress, N_("show progress")), |
| 58 | + OPT_END(), |
| 59 | + }; |
| 60 | + |
| 61 | + if (argc == 2 && !strcmp(argv[1], "-h")) |
| 62 | + usage_with_options(survey_usage, survey_options); |
| 63 | + |
| 64 | + ctx.repo = repo; |
| 65 | + |
| 66 | + prepare_repo_settings(ctx.repo); |
| 67 | + survey_load_config(&ctx); |
| 68 | + |
| 69 | + argc = parse_options(argc, argv, prefix, survey_options, survey_usage, 0); |
| 70 | + |
| 71 | + if (ctx.opts.show_progress < 0) |
| 72 | + ctx.opts.show_progress = isatty(2); |
| 73 | + |
| 74 | + return 0; |
| 75 | +} |
0 commit comments