Skip to content

Conversation

@heshiyingx
Copy link

If a variable has a default value set, when using the variable, pass arguments to the parameter in the form of '--flag arg'. The default value will be overridden by the provided value.

…le, pass arguments to the parameter in the form of "--flag arg". The default value will be overridden by the provided value.

Signed-off-by: hsy <[email protected]>
@CLAassistant
Copy link

CLAassistant commented May 28, 2024

CLA assistant check
All committers have signed the CLA.

Comment on lines -994 to 1014
value = split[1]
} else if flag.NoOptDefVal != "" {
// '--flag' (arg was optional)
value = flag.NoOptDefVal
} else if len(a) > 0 {
// '--flag arg'
value = a[0]
a = a[1:]
} else if flag.NoOptDefVal != "" {
// '--flag' (arg was optional)
value = flag.NoOptDefVal
} else {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't looked exactly why, but it looks like this patch can cause a regression; I tried using the NoOptDefVal on a flag (--pull), and it now failed when the flag before it is a boolean;

docker run -it --rm --pull=never alpine

invalid argument "--pull=never" for "--rm" flag: strconv.ParseBool: parsing "--pull=never": invalid syntax

Maybe because boolean flags have an implicit NoOptDefVal ?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried using the NoOptDefVal on a flag (--pull), and it now failed when the flag before it is a boolean;

Actually; same happens without that option set on the --pull flag, and I see the same for other flags;

docker run -it --rm --label foo=bar alpine
invalid argument "--label" for "--rm" flag: strconv.ParseBool: parsing "--label": invalid syntax

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants