#ifndef PARSE_OPTIONS_H #define PARSE_OPTIONS_H #include "gettext.h" struct repository; /** * Refer to Documentation/technical/api-parse-options.adoc for the API doc. */ enum parse_opt_type { /* special types */ OPTION_END, OPTION_GROUP, OPTION_NUMBER, OPTION_ALIAS, OPTION_SUBCOMMAND, /* options with no arguments */ OPTION_BIT, OPTION_NEGBIT, OPTION_BITOP, OPTION_COUNTUP, OPTION_SET_INT, /* options with arguments (usually) */ OPTION_STRING, OPTION_INTEGER, OPTION_UNSIGNED, OPTION_CALLBACK, OPTION_LOWLEVEL_CALLBACK, OPTION_FILENAME }; enum parse_opt_flags { PARSE_OPT_KEEP_DASHDASH = 1 << 0, PARSE_OPT_STOP_AT_NON_OPTION = 1 << 1, PARSE_OPT_KEEP_ARGV0 = 1 << 2, PARSE_OPT_KEEP_UNKNOWN_OPT = 1 << 3, PARSE_OPT_NO_INTERNAL_HELP = 1 << 4, PARSE_OPT_ONE_SHOT = 1 << 5, PARSE_OPT_SHELL_EVAL = 1 << 6, PARSE_OPT_SUBCOMMAND_OPTIONAL = 1 << 7, }; enum parse_opt_option_flags { PARSE_OPT_OPTARG = 1 << 0, PARSE_OPT_NOARG = 1 << 1, PARSE_OPT_NONEG = 1 << 2, PARSE_OPT_HIDDEN = 1 << 3, PARSE_OPT_LASTARG_DEFAULT = 1 << 4, PARSE_OPT_NODASH = 1 << 5, PARSE_OPT_LITERAL_ARGHELP = 1 << 6, PARSE_OPT_FROM_ALIAS = 1 << 7, PARSE_OPT_NOCOMPLETE = 1 << 9, PARSE_OPT_COMP_ARG = 1 << 10, PARSE_OPT_CMDMODE = 1 << 11, }; enum parse_opt_result { PARSE_OPT_COMPLETE = -3, PARSE_OPT_HELP = -2, PARSE_OPT_ERROR = -1, /* must be the same as error() */ PARSE_OPT_DONE = 0, /* fixed so that "return 0" works */ PARSE_OPT_NON_OPTION, PARSE_OPT_SUBCOMMAND, PARSE_OPT_UNKNOWN }; struct option; typedef int parse_opt_cb(const struct option *, const char *arg, int unset); struct parse_opt_ctx_t; typedef enum parse_opt_result parse_opt_ll_cb(struct parse_opt_ctx_t *ctx, const struct option *opt, const char *arg, int unset); typedef int parse_opt_subcommand_fn(int argc, const char **argv, const char *prefix, struct repository *repo); /* * `type`:: * holds the type of the option, you must have an OPTION_END last in your * array. * * `short_name`:: * the character to use as a short option name, '\0' if none. * * `long_name`:: * the long option (without the leading dashes) or subcommand name, * NULL if none. * * `value`:: * stores pointers to the values to be filled. * * `precision`:: * precision of the integer pointed to by `value` in number of bytes. Should * typically be its `sizeof()`. * * `argh`:: * token to explain the kind of argument this option wants. Does not * begin in capital letter, and does not end with a full stop. * Should be wrapped by N_() for translation. * Is automatically enclosed in brackets when printed, unless it * contains any of the following characters: ()<>[]| * E.g. "name" is shown as "" to indicate that a name value * needs to be supplied, not the literal string "name", but * "," and "(this|that)" are printed verbatim. * * `help`:: * the short help associated to what the option does. * Must never be NULL (except for OPTION_END and OPTION_SUBCOMMAND). * OPTION_GROUP uses this pointer to store the group header. * Should be wrapped by N_() for translation. * * `flags`:: * mask of parse_opt_option_flags. * PARSE_OPT_OPTARG: says that the argument is optional (not for BOOLEANs) * PARSE_OPT_NOARG: says that this option does not take an argument * PARSE_OPT_NONEG: says that this option cannot be negated * (i.e. rejects "--no-