32
p->argc--;
33
*arg = *++p->argv;
34
} else
35
- return opterror(opt, "requires a value", flags);
35
+ return error(_("%s requires a value"), optname(opt, flags));
36
return 0;
37
}
38
49
int flags)
50
{
51
const struct option *that;
52
- struct strbuf message = STRBUF_INIT;
52
struct strbuf that_name = STRBUF_INIT;
53
54
/*
66
strbuf_addf(&that_name, "--%s", that->long_name);
67
else
68
strbuf_addf(&that_name, "-%c", that->short_name);
70
- strbuf_addf(&message, ": incompatible with %s", that_name.buf);
69
+ error(_("%s is incompatible with %s"),
70
+ optname(opt, flags), that_name.buf);
71
strbuf_release(&that_name);
72
- opterror(opt, message.buf, flags);
73
- strbuf_release(&message);
72
return -1;
73
}
76
- return opterror(opt, ": incompatible with something else", flags);
74
+ return error(_("%s : incompatible with something else"),
75
+ optname(opt, flags));
76
}
77
78
static int get_value(struct parse_opt_ctx_t *p,
85
int err;
86
87
if (unset && p->opt)
89
- return opterror(opt, "takes no value", flags);
88
+ return error(_("%s takes no value"), optname(opt, flags));
89
if (unset && (opt->flags & PARSE_OPT_NONEG))
91
- return opterror(opt, "isn't available", flags);
90
+ return error(_("%s isn't available"), optname(opt, flags));
91
if (!(flags & OPT_SHORT) && p->opt && (opt->flags & PARSE_OPT_NOARG))
93
- return opterror(opt, "takes no value", flags);
92
+ return error(_("%s takes no value"), optname(opt, flags));
93
94
switch (opt->type) {
95
case OPTION_LOWLEVEL_CALLBACK:
175
return -1;
176
*(int *)opt->value = strtol(arg, (char **)&s, 10);
177
if (*s)
179
- return opterror(opt, "expects a numerical value", flags);
178
+ return error(_("%s expects a numerical value"),
179
+ optname(opt, flags));
180
return 0;
181
182
case OPTION_MAGNITUDE:
191
if (get_arg(p, opt, flags, &arg))
192
return -1;
193
if (!git_parse_ulong(arg, opt->value))
194
- return opterror(opt,
195
- "expects a non-negative integer value with an optional k/m/g suffix",
196
- flags);
194
+ return error(_("%s expects a non-negative integer value"
195
+ " with an optional k/m/g suffix"),
196
+ optname(opt, flags));
197
return 0;
198
199
default:
257
if (!rest)
258
continue;
259
if (*rest == '=')
260
- return opterror(options, "takes no value", flags);
260
+ return error(_("%s takes no value"),
261
+ optname(options, flags));
262
if (*rest)
263
continue;
264
p->out[p->cpidx++] = arg - 2;
774
usage_with_options(usagestr, options);
775
}
776
776
-#undef opterror
777
-int opterror(const struct option *opt, const char *reason, int flags)
777
+const char *optname(const struct option *opt, int flags)
778
{
779
+ static struct strbuf sb = STRBUF_INIT;
780
+
781
+ strbuf_reset(&sb);
782
if (flags & OPT_SHORT)
780
- return error("switch `%c' %s", opt->short_name, reason);
781
- if (flags & OPT_UNSET)
782
- return error("option `no-%s' %s", opt->long_name, reason);
783
- return error("option `%s' %s", opt->long_name, reason);
783
+ strbuf_addf(&sb, "switch `%c'", opt->short_name);
784
+ else if (flags & OPT_UNSET)
785
+ strbuf_addf(&sb, "option `no-%s'", opt->long_name);
786
+ else
787
+ strbuf_addf(&sb, "option `%s'", opt->long_name);
788
+
789
+ return sb.buf;
790
}