mirror of
https://github.com/git/git.git
synced 2024-11-01 14:57:52 +01:00
3a9f0f41db
If options are aggregated, and that the whole token is an exact prefix of a long option that is longer than 2 letters, reject it. This is to prevent a common typo: $ git commit -amend to get interpreted as "commit all with message 'end'". The typo check isn't performed if there is no aggregation, because the stuck form is the recommended one. If we have `-o` being a valid short option that takes an argument, and --option a long one, then we _MUST_ accept -option as "'o' option with argument 'ption'", which is our official recommended form. Signed-off-by: Pierre Habouzit <madcoder@debian.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
37 lines
1 KiB
C
37 lines
1 KiB
C
#include "cache.h"
|
|
#include "parse-options.h"
|
|
|
|
static int boolean = 0;
|
|
static int integer = 0;
|
|
static char *string = NULL;
|
|
|
|
int main(int argc, const char **argv)
|
|
{
|
|
const char *usage[] = {
|
|
"test-parse-options <options>",
|
|
NULL
|
|
};
|
|
struct option options[] = {
|
|
OPT_BOOLEAN('b', "boolean", &boolean, "get a boolean"),
|
|
OPT_INTEGER('i', "integer", &integer, "get a integer"),
|
|
OPT_INTEGER('j', NULL, &integer, "get a integer, too"),
|
|
OPT_GROUP("string options"),
|
|
OPT_STRING('s', "string", &string, "string", "get a string"),
|
|
OPT_STRING(0, "string2", &string, "str", "get another string"),
|
|
OPT_STRING(0, "st", &string, "st", "get another string (pervert ordering)"),
|
|
OPT_STRING('o', NULL, &string, "str", "get another string"),
|
|
OPT_END(),
|
|
};
|
|
int i;
|
|
|
|
argc = parse_options(argc, argv, options, usage, 0);
|
|
|
|
printf("boolean: %d\n", boolean);
|
|
printf("integer: %d\n", integer);
|
|
printf("string: %s\n", string ? string : "(not set)");
|
|
|
|
for (i = 0; i < argc; i++)
|
|
printf("arg %02d: %s\n", i, argv[i]);
|
|
|
|
return 0;
|
|
}
|