builtin / interpret-trailers.con commit trailer: put process_trailers() options into a struct (8abc898)
   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_STRING_LIST(0, "trailer", &trailers, N_("trailer"),
  28                                N_("trailer(s) to add")),
  29                OPT_END()
  30        };
  31
  32        argc = parse_options(argc, argv, prefix, options,
  33                             git_interpret_trailers_usage, 0);
  34
  35        if (argc) {
  36                int i;
  37                for (i = 0; i < argc; i++)
  38                        process_trailers(argv[i], &opts, &trailers);
  39        } else {
  40                if (opts.in_place)
  41                        die(_("no input file given for in-place editing"));
  42                process_trailers(NULL, &opts, &trailers);
  43        }
  44
  45        string_list_clear(&trailers, 0);
  46
  47        return 0;
  48}