summaryrefslogtreecommitdiff
path: root/parse-options.h
Commit message (Collapse)AuthorAgeFilesLines
* parse-options: add PARSE_OPT_LASTARG_DEFAULT flagPierre Habouzit2008-07-091-0/+1
| | | | | | | | | | | 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-301-0/+1
| | | | | | | 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-301-0/+5
| | | | | | | | | | | | 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-301-0/+4
| | | | | | | | 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-301-0/+9
| | | | | 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-301-0/+16
| | | | | | | 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-271-0/+4
| | | | | | | | | 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-111-0/+1
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * 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-011-0/+1
| | | | | | | | | | 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-021-0/+2
|/ | | | | | | 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-221-0/+3
| | | | | | | | | | | 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-111-1/+14
| | | | | | | | | | | | | | | | | | | | | 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-051-2/+35
| | | | Signed-off-by: Junio C Hamano <gitster@pobox.com>
* parse-options: allow callbacks to take no arguments at all.Pierre Habouzit2007-10-291-0/+1
| | | | | 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-291-0/+11
| | | | | | | 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-291-0/+16
| | | | | | | | | | | | | | | | | | | | | | * 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-291-4/+11
| | | | | 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-291-0/+35
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>