aboutsummaryrefslogtreecommitdiff
path: root/parse-options.h
Commit message (Collapse)AuthorAge
* Merge branch 'gs/usage-to-stdout'Junio C Hamano2010-06-21
|\ | | | | | | | | | | | | | | | | * gs/usage-to-stdout: parseopt: wrap rev-parse --parseopt usage for eval consumption print the usage string on stdout instead of stderr Conflicts: parse-options.h
| * parseopt: wrap rev-parse --parseopt usage for eval consumptionThomas Rast2010-06-13
| | | | | | | | | | | | | | | | | | | | | | | | | | 9c7304e (print the usage string on stdout instead of stderr, 2010-05-17) broke rev-parse --parseopt: when run with -h, the usage notice on stdout ended up in the shell eval. Wrap the usage in a cat <<\EOF ... EOF block when printing to stdout. I do not expect any usage lines to ever start with EOF so this shouldn't be an undue burden. Signed-off-by: Thomas Rast <trast@student.ethz.ch> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* | enums: omit trailing comma for portabilityGary V. Vaughan2010-05-31
|/ | | | | | | | | | | | | | | | | | | Without this patch at least IBM VisualAge C 5.0 (I have 5.0.2) on AIX 5.1 fails to compile git. enum style is inconsistent already, with some enums declared on one line, some over 3 lines with the enum values all on the middle line, sometimes with 1 enum value per line... and independently of that the trailing comma is sometimes present and other times absent, often mixing with/without trailing comma styles in a single file, and sometimes in consecutive enum declarations. Clearly, omitting the comma is the more portable style, and this patch changes all enum declarations to use the portable omitted dangling comma style consistently. Signed-off-by: Gary V. Vaughan <gary@thewrittenword.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* parse-options: add parse_options_concat() to concat optionsJunio C Hamano2010-03-06
| | | | | Signed-off-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* Add an optional argument for --color optionsMark Lodato2010-02-18
| | | | | | | | | | | | | | | | | | | | | | | | Make git-branch, git-show-branch, git-grep, and all the diff-based programs accept an optional argument <when> for --color. The argument is a colorbool: "always", "never", or "auto". If no argument is given, "always" is used; --no-color is an alias for --color=never. This makes the command-line interface consistent with other GNU tools, such as `ls' and `grep', and with the git-config color options. Note that, without an argument, --color and --no-color work exactly as before. To implement this, two internal changes were made: 1. Allow the first argument of git_config_colorbool() to be NULL, in which case it returns -1 if the argument isn't "always", "never", or "auto". 2. Add OPT_COLOR_FLAG(), OPT__COLOR(), and parse_opt_color_flag_cb() to the option parsing library. The callback uses git_config_colorbool(), so color.h is now a dependency of parse-options.c. Signed-off-by: Mark Lodato <lodatom@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* Merge branch 'jc/symbol-static'Junio C Hamano2010-01-20
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * jc/symbol-static: date.c: mark file-local function static Replace parse_blob() with an explanatory comment symlinks.c: remove unused functions object.c: remove unused functions strbuf.c: remove unused function sha1_file.c: remove unused function mailmap.c: remove unused function utf8.c: mark file-local function static submodule.c: mark file-local function static quote.c: mark file-local function static remote-curl.c: mark file-local function static read-cache.c: mark file-local functions static parse-options.c: mark file-local function static entry.c: mark file-local function static http.c: mark file-local functions static pretty.c: mark file-local function static builtin-rev-list.c: mark file-local function static bisect.c: mark file-local function static
| * parse-options.c: mark file-local function staticJunio C Hamano2010-01-12
| | | | | | | | Signed-off-by: Junio C Hamano <gitster@pobox.com>
* | Teach --[no-]rerere-autoupdate option to merge, revert and friendsJunio C Hamano2009-12-04
|/ | | | | | | Introduce a command line option to override rerere.autoupdate configuration variable to make it more useful. Signed-off-by: Junio C Hamano <gitster@pobox.com>
* Merge branch 'cc/replace'Junio C Hamano2009-08-21
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * cc/replace: t6050: check pushing something based on a replaced commit Documentation: add documentation for "git replace" Add git-replace to .gitignore builtin-replace: use "usage_msg_opt" to give better error messages parse-options: add new function "usage_msg_opt" builtin-replace: teach "git replace" to actually replace Add new "git replace" command environment: add global variable to disable replacement mktag: call "check_sha1_signature" with the replacement sha1 replace_object: add a test case object: call "check_sha1_signature" with the replacement sha1 sha1_file: add a "read_sha1_file_repl" function replace_object: add mechanism to replace objects found in "refs/replace/" refs: add a "for_each_replace_ref" function
| * parse-options: add new function "usage_msg_opt"Christian Couder2009-05-31
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This function can be used instead of "usage_with_options" when you want to print an error message before the usage string. It may be useful because: if (condition) usage_msg_opt("condition is false", usage, opts); is shorter than: if (condition) { fprintf(stderr, "condition is false\n\n"); usage_with_options(usage, opts); } and may be more consistent. Signed-off-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* | parse-opt: optionally show "--no-" option stringJohannes Schindelin2009-07-31
| | | | | | | | | | | | | | | | | | | | | | It is usually better to have positive options, to avoid confusing double negations. However, sometimes it is desirable to show the negative option in the help. Introduce the flag PARSE_OPT_NEGHELP to do that. Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* | Merge branch 'sb/parse-options-integer'Junio C Hamano2009-06-18
|\ \ | | | | | | | | | | | | | | | * sb/parse-options-integer: parse-options: simplify usage argh handling parse-options: make OPT_INTEGER's argh explicit
| * | parse-options: simplify usage argh handlingStephen Boyd2009-06-06
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Simplify the argh printing by simply calling usage_argh() if the option can take an argument. Update macros defined in parse-options.h to set the PARSE_OPT_NOARG flag. The only other user of custom non-argument taking options is git-apply (in this case OPTION_BOOLEAN for deprecated options). Update it to set the PARSE_OPT_NOARG flag. Thanks to Ren辿 Scharfe for the suggestion and starter patch. Signed-off-by: Stephen Boyd <bebarino@gmail.com> Reviewd-by: René Scharfe <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <gitster@pobox.com>
| * | parse-options: make OPT_INTEGER's argh explicitStephen Boyd2009-06-06
| |/ | | | | | | | | | | | | | | | | | | | | | | | | | | OPTION_INTEGER hardcodes its argh member to be "n", but the decision is hidden deep in usage_with_options_internal(). Make "n" the default argh for the OPT_INTEGER macro while leaving it undecided for the OPTION_INTEGER enum. This makes it less surprising to users that argh is "n" when using the OPT_INTEGER macro. Signed-off-by: Stephen Boyd <bebarino@gmail.com> Reviewed-by: René Scharfe <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* | show-branch: don't use LASTARG_DEFAULT with OPTARGStephen Boyd2009-06-09
|/ | | | | | | | | | | | | | 5734365 (show-branch: migrate to parse-options API 2009-05-21) incorrectly set the --more option's flags to be PARSE_OPT_LASTARG_DEFAULT and PARSE_OPT_OPTARG. These two flags shouldn't be used together. An option taking a default should just set the default value desired and parse options will take care of the rest. Update the header comment to better convey this information. Signed-off-by: Stephen Boyd <bebarino@gmail.com> Acked-by: René Scharfe <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* parse-opts: add OPT_FILENAME and transition builtinsStephen Boyd2009-05-25
| | | | | | | | | | | | | | | | | | | | | | Commit dbd0f5c (Files given on the command line are relative to $cwd, 2008-08-06) introduced parse_options_fix_filename() as a minimal fix. OPT_FILENAME is intended to be a more robust fix for the same issue. OPT_FILENAME and its associated enum OPTION_FILENAME are used to represent filename options within the parse options API. This option is similar to OPTION_STRING. If --no is prefixed to the option the filename is unset. If no argument is given and the default value is set, the filename is set to the default value. The difference is that the filename is prefixed with the prefix passed to parse_options() (or parse_options_start()). Update git-apply, git-commit, git-fmt-merge-msg, and git-tag to use OPT_FILENAME with their filename options. Also, rename parse_options_fix_filename() to fix_filename() as it is no longer extern. Signed-off-by: Stephen Boyd <bebarino@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* parse-opts: prepare for OPT_FILENAMEStephen Boyd2009-05-25
| | | | | | | | | | To give OPT_FILENAME the prefix, we pass the prefix to parse_options() which passes the prefix to parse_options_start() which sets the prefix member of parse_opts_ctx accordingly. If there isn't a prefix in the calling context, passing NULL will suffice. Signed-off-by: Stephen Boyd <bebarino@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* Merge branch 'sb/show-branch-parse-options' into sb/opt-filenameJunio C Hamano2009-05-25
|\ | | | | | | | | | | | | | | | | * sb/show-branch-parse-options: show-branch: migrate to parse-options API parse-options: add PARSE_OPT_LITERAL_ARGHELP for complicated argh's Conflicts: parse-options.h
| * parse-options: add PARSE_OPT_LITERAL_ARGHELP for complicated argh'sStephen Boyd2009-05-22
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Usually, the argh element in struct option points at a placeholder value (e.g. "val"), and is shown in the usage message as --option=<val> by enclosing the string inside of angle brackets. When the option is more complex (e.g. optional arguments separated by a comma), you would want to produce a usage message that looks like --option=<val1>[,<val2>] In such a case, the caller can pass a string to argh with placeholders already enclosed in necessary angle brackets (e.g. "<val1>[,<val2>]") and set this flag. Signed-off-by: Stephen Boyd <bebarino@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* | parseopt: add PARSE_OPT_NODASHRené Scharfe2009-05-09
| | | | | | | | | | | | | | | | | | Add support for options that don't start with a dash. Initially, they don't accept arguments and can only be short options, i.e. consist of a single character. Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* | parseopt: add OPT_NUMBER_CALLBACKRené Scharfe2009-05-09
| | | | | | | | | | | | | | | | Add a way to recognize numerical options. The number is passed to a callback function as a string. Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* | parseopt: add OPT_NEGBITRené Scharfe2009-05-09
|/ | | | | | | | | | | | Add OPTION_NEGBIT and OPT_NEGBIT, mirroring OPTION_BIT and OPT_BIT. OPT_NEGBIT can be used together with OPT_BIT to define two options that cancel each other out. Note: this patch removes the reminder from the test script because it adds a test for --no-or4 and there already was one for --or4. Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* Fix typos / spelling in commentsMike Ralphson2009-04-22
| | | | | Signed-off-by: Mike Ralphson <mike@abacus.co.uk> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* parseopt: add PARSE_OPT_NO_INTERNAL_HELPRené Scharfe2009-03-08
| | | | | | | | | Add a parseopt flag, PARSE_OPT_NO_INTERNAL_HELP, that turns off internal handling of -h, --help and --help-all. This allows the implementation of custom help option handlers or incremental parsers. Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* parseopt: add PARSE_OPT_KEEP_UNKNOWNRené Scharfe2009-03-08
| | | | | | | | Add a parseopt flag, PARSE_OPT_KEEP_UNKNOWN, that can be used to keep unknown options in argv, similar to the existing KEEP flags. Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* Make opt_parse_with_commit() non-staticJake Goulding2009-01-28
| | | | | | | | | Moving opt_parse_with_commit() from branch to a common location, in preparation for using it in tag. Rename it to match naming convention of other option parsing functions. Signed-off-by: Jake Goulding <goulding@vivisimo.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* Teach/Fix pull/fetch -q/-v optionsTuncer Ayaz2008-11-14
| | | | | | | | Implement git-pull --quiet and git-pull --verbose by adding the options to git-pull and fixing verbosity handling in git-fetch. Signed-off-by: Junio C Hamano <gitster@pobox.com>
* Sync with 1.5.6.5Junio C Hamano2008-08-06
|\
| * Files given on the command line are relative to $cwdJunio C Hamano2008-08-06
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When running "git commit -F file" and "git tag -F file" from a subdirectory, we should take it as relative to the directory we started from, not relative to the top-level directory. This adds a helper function "parse_options_fix_filename()" to make it more convenient to fix this class of issues. Ideally, parse_options() should support a new type of option, "OPT_FILENAME", to do this uniformly, but this patch is meant to go to 'maint' to fix it minimally. One thing to note is that value for "commit template file" that comes from the command line is taken as relative to $cwd just like other parameters, but when it comes from the configuration varilable 'commit.template', it is taken as relative to the working tree root as before. I think this difference actually is sensible (not that I particularly think commit.template itself is sensible). Signed-off-by: Junio C Hamano <gitster@pobox.com>
* | parse-options: add PARSE_OPT_LASTARG_DEFAULT flagPierre Habouzit2008-07-09
| | | | | | | | | | | | | | | | | | | | | | If you set this for a given option, and the optoin appears without an argument on the command line, then the `defval' is used as its argument. Note that this flag is meaningless in presence of OPTARG or NOARG flags. (in the current implementation it will be ignored, but don't rely on it). Signed-off-by: Pierre Habouzit <madcoder@debian.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* | parse-opt: add PARSE_OPT_KEEP_ARGV0 parser option.Pierre Habouzit2008-06-30
| | | | | | | | | | | | | | This way, argv[0] isn't clobbered when parse-options filters argv[]. Signed-off-by: Pierre Habouzit <madcoder@debian.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* | parse-opt: fake short strings for callers to believe in.Pierre Habouzit2008-06-30
| | | | | | | | | | | | | | | | | | | | | | | | If we begin to parse -abc and that the parser knew about -a and -b, it will fake a -c switch for the caller to deal with. Of course in the case of -acb (supposing -c is not taking an argument) the caller will have to be especially clever to do the same thing. We could think about exposing an API to do so if it's really needed, but oh well... Signed-off-by: Pierre Habouzit <madcoder@debian.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* | parse-opt: create parse_options_step.Pierre Habouzit2008-06-30
| | | | | | | | | | | | | | | | For now it's unable to stop at unknown options, this commit merely reorganize some code around. Signed-off-by: Pierre Habouzit <madcoder@debian.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* | parse-opt: Export a non NORETURN usage dumper.Pierre Habouzit2008-06-30
| | | | | | | | | | Signed-off-by: Pierre Habouzit <madcoder@debian.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* | parse-opt: have parse_options_{start,end}.Pierre Habouzit2008-06-30
|/ | | | | | | Make the struct optparse_t public under the better name parse_opt_ctx_t. Signed-off-by: Pierre Habouzit <madcoder@debian.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* parse-options.c: introduce OPT_DATEMichele Ballabio2008-03-27
| | | | | | | | | There are quite a few places that will need to call approxidate(), when they'll adopt the parse-options system, so this patch adds the function parse_opt_approxidate_cb(), used by OPT_DATE. Signed-off-by: Michele Ballabio <barra_cuda@katamail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* Merge branch 'js/remote'Junio C Hamano2008-03-11
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * js/remote: "remote update": print remote name being fetched from builtin remote rm: remove symbolic refs, too remote: fix "update [group...]" remote show: Clean up connection correctly if object fetch wasn't done builtin-remote: prune remotes correctly that were added with --mirror Make git-remote a builtin Test "git remote show" and "git remote prune" parseopt: add flag to stop on first non option path-list: add functions to work with unsorted lists Conflicts: parse-options.c
| * parseopt: add flag to stop on first non optionJohannes Schindelin2008-03-01
| | | | | | | | | | Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* | parse-options: new option type to treat an option-like parameter as an argument.Pierre Habouzit2008-03-02
|/ | | | | | | This is meant to be used to keep --not and --all during revision parsing. Signed-off-by: Pierre Habouzit <madcoder@debian.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* parse-options: Allow to hide options from the default usage.Pierre Habouzit2007-11-22
| | | | | | | | | | | This is useful for backward-compatibility aliases, or very advanced command line switches introduced for internal git usages and have no real use for a user. parse-options still shows them if the user asks for --help-all. Signed-off-by: Pierre Habouzit <madcoder@debian.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* parse-options new features.Pierre Habouzit2007-11-11
| | | | | | | | | | | | | | | | | | | | | options flags: ~~~~~~~~~~~~~ PARSE_OPT_NONEG allow the caller to disallow the negated option to exists. option types: ~~~~~~~~~~~~ OPTION_BIT: ORs (or NANDs) a mask. OPTION_SET_INT: force the value to be set to this integer. OPTION_SET_PTR: force the value to be set to this pointer. helper: ~~~~~~ HAS_MULTI_BITS (in git-compat-util.h) is a bit-hack to check if an unsigned integer has more than one bit set, useful to check if conflicting options have been used. Signed-off-by: Pierre Habouzit <madcoder@debian.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* Some better parse-options documentation.Pierre Habouzit2007-11-05
| | | | Signed-off-by: Junio C Hamano <gitster@pobox.com>
* parse-options: allow callbacks to take no arguments at all.Pierre Habouzit2007-10-29
| | | | | Signed-off-by: Pierre Habouzit <madcoder@debian.org> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
* Add shortcuts for very often used options.Pierre Habouzit2007-10-29
| | | | | | | It helps with consistency of the help strings, for example. Signed-off-by: Pierre Habouzit <madcoder@debian.org> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
* parse-options: make some arguments optional, add callbacks.Pierre Habouzit2007-10-29
| | | | | | | | | | | | | | | | | | | | | | * add the possibility to use callbacks to parse some options, this can help implementing new options kinds with great flexibility. struct option gains a callback pointer and a `defval' where callbacks user can put either integers or pointers. callbacks also can use the `value' pointer for anything, preferably to the pointer to the final storage for the value though. * add a `flag' member to struct option to make explicit that this option may have an optional argument. The semantics depends on the option type. For INTEGERS, it means that if the switch is not used in its --long-form=<value> form, and that there is no token after it or that the token does not starts with a digit, then it's assumed that the switch has no argument. For STRING or CALLBACK it works the same, except that the condition is that the next atom starts with a dash. This is needed to implement backward compatible behaviour with existing ways to parse the command line. Its use for new options is discouraged. Signed-off-by: Pierre Habouzit <madcoder@debian.org> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
* parse-options: be able to generate usages automaticallyPierre Habouzit2007-10-29
| | | | | Signed-off-by: Pierre Habouzit <madcoder@debian.org> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
* Add a simple option parser.Pierre Habouzit2007-10-29
The option parser takes argc, argv, an array of struct option and a usage string. Each of the struct option elements in the array describes a valid option, its type and a pointer to the location where the value is written. The entry point is parse_options(), which scans through the given argv, and matches each option there against the list of valid options. During the scan, argv is rewritten to only contain the non-option command line arguments and the number of these is returned. Aggregation of single switches is allowed: -rC0 is the same as -r -C 0 (supposing that -C wants an arg). Every long option automatically support the option with the same name, prefixed with 'no-' to unset the switch. It assumes that initial value for strings are "NULL" and for integers is "0". Long options are supported either with '=' or without: --some-option=foo is the same as --some-option foo Acked-by: Kristian Høgsberg <krh@redhat.com> Signed-off-by: Pierre Habouzit <madcoder@debian.org> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>