Ramkumar Ramachandra [off-list ref] writes:
When the option parser encounters an OPTION_INTEGER argument,
PARSE_OPT_NOARG should imply that the default value should be used.
Sorry but why?
Doesn't NOARG mean "Do not take an argument, if you give me an argument
that is an error"?
I would understand if this were OPT_OPTARG, though.
Confused...
quoted hunk
Signed-off-by: Ramkumar Ramachandra <redacted>
Cc: Jakub Narebski <redacted>
---
parse-options.c | 3 +++
1 files changed, 3 insertions(+), 0 deletions(-)
diff --git a/parse-options.c b/parse-options.c
index e0c3641..7ec9886 100644
--- a/parse-options.c
+++ b/parse-options.c
@@ -138,6 +138,9 @@ static int get_value(struct parse_opt_ctx_t *p,
*(int *)opt->value = 0;
return 0;
}
+ if (opt->flags & PARSE_OPT_NOARG)
+ *(int *)opt->value = opt->defval;
+ return 0;
if (opt->flags & PARSE_OPT_OPTARG && !p->opt) {
*(int *)opt->value = opt->defval;
return 0;--
1.7.2.2.409.gdbb11.dirty
Hi Junio,
Junio C Hamano writes:
Ramkumar Ramachandra [off-list ref] writes:
quoted
When the option parser encounters an OPTION_INTEGER argument,
PARSE_OPT_NOARG should imply that the default value should be used.
Sorry but why?
Doesn't NOARG mean "Do not take an argument, if you give me an argument
that is an error"?
Oh, does it mean that? I might have interpreted the description in
`parse-options.h` too literally: "says that this option takes no
argument". So I'm handling the case when an integer option is
specified, but no integer argument is given.
I would understand if this were OPT_OPTARG, though.
That case is already handled. The condition (opt->flags & PARSE_OPT_OPTARG &&
!p->opt) does the same thing.
Confused...
Okay, let me explain. Let's say I want to have an option that takes an
integer argument, say `foo`. To set it to the integer argument 42, I
can say `--foo=42`. To set it to its default value, I could earlier
say `--foo=`. With this patch I can simply say `--foo`. Makes sense?
-- Ram
Hi Ram,
[rearranged for convenience]
Ramkumar Ramachandra wrote:
Let's say I want to have an option that takes an
integer argument, say `foo`. To set it to the integer argument 42, I
can say `--foo=42`. To set it to its default value, I could earlier
say `--foo=`. With this patch I can simply say `--foo`. Makes sense?
I think you want OPTARG ("optional argument").
What your patch would allow is using OPTION_INTEGER for boolean
options, where people use OPT_SET_INT now. Maybe that would be a good
cleanup, but I am not convinced it is worth the churn.
Junio C Hamano writes:
quoted
Doesn't NOARG mean "Do not take an argument, if you give me an argument
that is an error"?
Oh, does it mean that?
Yes.
-- 8< --
Subject: parse-options: clarify PARSE_OPT_NOARG description
Here "takes no argument" means "does not take an argument". The
latter phrasing might make it clearer that PARSE_OPT_NOARG does not
make an option with an argument that can optionally be left off.
Noticed-by: Ramkumar Ramachandra [off-list ref]
Signed-off-by: Jonathan Nieder <redacted>
---
diff --git a/parse-options.h b/parse-options.h
index 7435cdb..d982f0f 100644
--- a/parse-options.h
+++ b/parse-options.h
@@ -69,7 +69,7 @@ typedef int parse_opt_cb(const struct option *, const char *arg, int unset);
* `flags`::
* mask of parse_opt_option_flags.
* PARSE_OPT_OPTARG: says that the argument is optional (not for BOOLEANs)
- * PARSE_OPT_NOARG: says that this option takes no argument
+ * PARSE_OPT_NOARG: says that this option does not take an argument
* PARSE_OPT_NONEG: says that this option cannot be negated
* PARSE_OPT_HIDDEN: this option is skipped in the default usage, and
* shown only in the full usage.
--