]> asedeno.scripts.mit.edu Git - git.git/blobdiff - test-parse-options.c
Merge branch 'jk/no-no-no-empty-directory'
[git.git] / test-parse-options.c
index 6e18083a7d1655e9eabef197c58d92a910d2f67b..e0669dcb41d1d779f274e1ff785352e284953b14 100644 (file)
@@ -15,7 +15,13 @@ int length_callback(const struct option *opt, const char *arg, int unset)
        if (unset)
                return 1; /* do not support unset */
 
-       *(unsigned long *)opt->value = strlen(arg);
+       *(int *)opt->value = strlen(arg);
+       return 0;
+}
+
+int number_callback(const struct option *opt, const char *arg, int unset)
+{
+       *(int *)opt->value = strtol(arg, NULL, 10);
        return 0;
 }
 
@@ -29,6 +35,7 @@ int main(int argc, const char **argv)
                OPT_BOOLEAN('b', "boolean", &boolean, "get a boolean"),
                OPT_BIT('4', "or4", &boolean,
                        "bitwise-or boolean with ...0100", 4),
+               OPT_NEGBIT(0, "neg-or4", &boolean, "same as --no-or4", 4),
                OPT_GROUP(""),
                OPT_INTEGER('i', "integer", &integer, "get a integer"),
                OPT_INTEGER('j', NULL, &integer, "get a integer, too"),
@@ -45,6 +52,10 @@ int main(int argc, const char **argv)
                        "set string to default", (unsigned long)"default"),
                OPT_GROUP("Magic arguments"),
                OPT_ARGUMENT("quux", "means --quux"),
+               OPT_NUMBER_CALLBACK(&integer, "set integer to NUM",
+                       number_callback),
+               { OPTION_BOOLEAN, '+', NULL, &boolean, NULL, "same as -b",
+                 PARSE_OPT_NOARG | PARSE_OPT_NONEG | PARSE_OPT_NODASH },
                OPT_GROUP("Standard options"),
                OPT__ABBREV(&abbrev),
                OPT__VERBOSE(&verbose),