]> git.ipfire.org Git - thirdparty/git.git/blobdiff - test-parse-options.c
parseopt: add OPT_NUMBER_CALLBACK
[thirdparty/git.git] / test-parse-options.c
index eddc0267a27323e40a41849f777df4dc4fed45a8..d46eac21b11f8e10f29105dc6bc7262496d33110 100644 (file)
@@ -19,6 +19,12 @@ int length_callback(const struct option *opt, const char *arg, int unset)
        return 0;
 }
 
+int number_callback(const struct option *opt, const char *arg, int unset)
+{
+       *(int *)opt->value = strtol(arg, NULL, 10);
+       return 0;
+}
+
 int main(int argc, const char **argv)
 {
        const char *usage[] = {
@@ -46,6 +52,8 @@ 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),
                OPT_GROUP("Standard options"),
                OPT__ABBREV(&abbrev),
                OPT__VERBOSE(&verbose),