]> git.ipfire.org Git - thirdparty/git.git/blame - test-parse-options.c
Replace uses of "git-var" with "git var"
[thirdparty/git.git] / test-parse-options.c
CommitLineData
beb47437
JS
1#include "cache.h"
2#include "parse-options.h"
3
4static int boolean = 0;
010a2dac
SB
5static unsigned long integer = 0;
6static int abbrev = 7;
7static int verbose = 0, dry_run = 0, quiet = 0;
beb47437
JS
8static char *string = NULL;
9
010a2dac
SB
10int length_callback(const struct option *opt, const char *arg, int unset)
11{
12 printf("Callback: \"%s\", %d\n",
13 (arg ? arg : "not set"), unset);
14 if (unset)
15 return 1; /* do not support unset */
16
17 *(unsigned long *)opt->value = strlen(arg);
18 return 0;
19}
20
beb47437
JS
21int main(int argc, const char **argv)
22{
23 const char *usage[] = {
24 "test-parse-options <options>",
25 NULL
26 };
27 struct option options[] = {
28 OPT_BOOLEAN('b', "boolean", &boolean, "get a boolean"),
010a2dac
SB
29 OPT_BIT('4', "or4", &boolean,
30 "bitwise-or boolean with ...0100", 4),
31 OPT_GROUP(""),
beb47437
JS
32 OPT_INTEGER('i', "integer", &integer, "get a integer"),
33 OPT_INTEGER('j', NULL, &integer, "get a integer, too"),
010a2dac
SB
34 OPT_SET_INT(0, "set23", &integer, "set integer to 23", 23),
35 OPT_DATE('t', NULL, &integer, "get timestamp of <time>"),
36 OPT_CALLBACK('L', "length", &integer, "str",
37 "get length of <str>", length_callback),
38 OPT_GROUP("String options"),
beb47437
JS
39 OPT_STRING('s', "string", &string, "string", "get a string"),
40 OPT_STRING(0, "string2", &string, "str", "get another string"),
243e0614 41 OPT_STRING(0, "st", &string, "st", "get another string (pervert ordering)"),
3a9f0f41 42 OPT_STRING('o', NULL, &string, "str", "get another string"),
010a2dac
SB
43 OPT_SET_PTR(0, "default-string", &string,
44 "set string to default", (unsigned long)"default"),
45 OPT_GROUP("Magic arguments"),
580d5bff 46 OPT_ARGUMENT("quux", "means --quux"),
010a2dac
SB
47 OPT_GROUP("Standard options"),
48 OPT__ABBREV(&abbrev),
49 OPT__VERBOSE(&verbose),
50 OPT__DRY_RUN(&dry_run),
51 OPT__QUIET(&quiet),
beb47437
JS
52 OPT_END(),
53 };
54 int i;
55
56 argc = parse_options(argc, argv, options, usage, 0);
57
58 printf("boolean: %d\n", boolean);
010a2dac 59 printf("integer: %lu\n", integer);
beb47437 60 printf("string: %s\n", string ? string : "(not set)");
010a2dac
SB
61 printf("abbrev: %d\n", abbrev);
62 printf("verbose: %d\n", verbose);
63 printf("quiet: %s\n", quiet ? "yes" : "no");
64 printf("dry run: %s\n", dry_run ? "yes" : "no");
beb47437
JS
65
66 for (i = 0; i < argc; i++)
67 printf("arg %02d: %s\n", i, argv[i]);
68
69 return 0;
70}