builtin / interpret-trailers.con commit interpret-trailers: add an option to unfold values (0000239)
   1/*
   2 * Builtin "git interpret-trailers"
   3 *
   4 * Copyright (c) 2013, 2014 Christian Couder <chriscool@tuxfamily.org>
   5 *
   6 */
   7
   8#include "cache.h"
   9#include "builtin.h"
  10#include "parse-options.h"
  11#include "string-list.h"
  12#include "trailer.h"
  13
  14static const char * const git_interpret_trailers_usage[] = {
  15        N_("git interpret-trailers [--in-place] [--trim-empty] [(--trailer <token>[(=|:)<value>])...] [<file>...]"),
  16        NULL
  17};
  18
  19int cmd_interpret_trailers(int argc, const char **argv, const char *prefix)
  20{
  21        struct process_trailer_options opts = PROCESS_TRAILER_OPTIONS_INIT;
  22        struct string_list trailers = STRING_LIST_INIT_NODUP;
  23
  24        struct option options[] = {
  25                OPT_BOOL(0, "in-place", &opts.in_place, N_("edit files in place")),
  26                OPT_BOOL(0, "trim-empty", &opts.trim_empty, N_("trim empty trailers")),
  27                OPT_BOOL(0, "only-trailers", &opts.only_trailers, N_("output only the trailers")),
  28                OPT_BOOL(0, "only-input", &opts.only_input, N_("do not apply config rules")),
  29                OPT_BOOL(0, "unfold", &opts.unfold, N_("join whitespace-continued values")),
  30                OPT_STRING_LIST(0, "trailer", &trailers, N_("trailer"),
  31                                N_("trailer(s) to add")),
  32                OPT_END()
  33        };
  34
  35        argc = parse_options(argc, argv, prefix, options,
  36                             git_interpret_trailers_usage, 0);
  37
  38        if (opts.only_input && trailers.nr)
  39                usage_msg_opt(
  40                        _("--trailer with --only-input does not make sense"),
  41                        git_interpret_trailers_usage,
  42                        options);
  43
  44        if (argc) {
  45                int i;
  46                for (i = 0; i < argc; i++)
  47                        process_trailers(argv[i], &opts, &trailers);
  48        } else {
  49                if (opts.in_place)
  50                        die(_("no input file given for in-place editing"));
  51                process_trailers(NULL, &opts, &trailers);
  52        }
  53
  54        string_list_clear(&trailers, 0);
  55
  56        return 0;
  57}