61
#define TYPE_PATH 4
62
#define TYPE_EXPIRY_DATE 5
63
64
+#define OPT_CALLBACK_VALUE(s, l, v, h, i) \
65
+ { OPTION_CALLBACK, (s), (l), (v), NULL, (h), PARSE_OPT_NOARG | \
66
+ PARSE_OPT_NONEG, option_parse_type, (i) }
67
+
68
+static struct option builtin_config_options[];
69
+
70
+static int option_parse_type(const struct option *opt, const char *arg,
71
+ int unset)
72
+{
73
+ int new_type, *to_type;
74
+
75
+ if (unset) {
76
+ *((int *) opt->value) = 0;
77
+ return 0;
78
+ }
79
+
80
+ /*
81
+ * To support '--<type>' style flags, begin with new_type equal to
82
+ * opt->defval.
83
+ */
84
+ new_type = opt->defval;
85
+ if (!new_type) {
86
+ if (!strcmp(arg, "bool"))
87
+ new_type = TYPE_BOOL;
88
+ else if (!strcmp(arg, "int"))
89
+ new_type = TYPE_INT;
90
+ else if (!strcmp(arg, "bool-or-int"))
91
+ new_type = TYPE_BOOL_OR_INT;
92
+ else if (!strcmp(arg, "path"))
93
+ new_type = TYPE_PATH;
94
+ else if (!strcmp(arg, "expiry-date"))
95
+ new_type = TYPE_EXPIRY_DATE;
96
+ else
97
+ die(_("unrecognized --type argument, %s"), arg);
98
+ }
99
+
100
+ to_type = opt->value;
101
+ if (*to_type && *to_type != new_type) {
102
+ /*
103
+ * Complain when there is a new type not equal to the old type.
104
+ * This allows for combinations like '--int --type=int' and
105
+ * '--type=int --type=int', but disallows ones like '--type=bool
106
+ * --int' and '--type=bool
107
+ * --type=int'.
108
+ */
109
+ error("only one type at a time.");
110
+ usage_with_options(builtin_config_usage,
111
+ builtin_config_options);
112
+ }
113
+ *to_type = new_type;
114
+
115
+ return 0;
116
+}
117
+
118
static struct option builtin_config_options[] = {
119
OPT_GROUP(N_("Config file location")),
120
OPT_BOOL(0, "global", &use_global_config, N_("use global config file")),
138
OPT_BIT(0, "get-color", &actions, N_("find the color configured: slot [default]"), ACTION_GET_COLOR),
139
OPT_BIT(0, "get-colorbool", &actions, N_("find the color setting: slot [stdout-is-tty]"), ACTION_GET_COLORBOOL),
140
OPT_GROUP(N_("Type")),
87
- OPT_SET_INT(0, "bool", &type, N_("value is \"true\" or \"false\""), TYPE_BOOL),
88
- OPT_SET_INT(0, "int", &type, N_("value is decimal number"), TYPE_INT),
89
- OPT_SET_INT(0, "bool-or-int", &type, N_("value is --bool or --int"), TYPE_BOOL_OR_INT),
90
- OPT_SET_INT(0, "path", &type, N_("value is a path (file or directory name)"), TYPE_PATH),
91
- OPT_SET_INT(0, "expiry-date", &type, N_("value is an expiry date"), TYPE_EXPIRY_DATE),
141
+ OPT_CALLBACK('t', "type", &type, "", N_("value is given this type"), option_parse_type),
142
+ OPT_CALLBACK_VALUE(0, "bool", &type, N_("value is \"true\" or \"false\""), TYPE_BOOL),
143
+ OPT_CALLBACK_VALUE(0, "int", &type, N_("value is decimal number"), TYPE_INT),
144
+ OPT_CALLBACK_VALUE(0, "bool-or-int", &type, N_("value is --bool or --int"), TYPE_BOOL_OR_INT),
145
+ OPT_CALLBACK_VALUE(0, "path", &type, N_("value is a path (file or directory name)"), TYPE_PATH),
146
+ OPT_CALLBACK_VALUE(0, "expiry-date", &type, N_("value is an expiry date"), TYPE_EXPIRY_DATE),
147
OPT_GROUP(N_("Other")),
148
OPT_BOOL('z', "null", &end_null, N_("terminate values with NUL byte")),
149
OPT_BOOL(0, "name-only", &omit_values, N_("show variable names only")),