Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Impossible to pass a negative number as the value for an option #89

Open
rpendleton opened this issue Mar 23, 2022 · 3 comments
Open

Impossible to pass a negative number as the value for an option #89

rpendleton opened this issue Mar 23, 2022 · 3 comments

Comments

@rpendleton
Copy link

If you configure an option to accept a number, it seems it's impossible to pass a negative number for the value of the option since it's interpreted as a flag instead.

I'm not 100% sure what the right way to resolve this would be without making a mess of things, but I figure it's something that should at least have a workaround.

Group {
    $0.command("submit", Option<Double>("nice", default: 0, flag: "n")) { niceValue in
        print(niceValue)
    }
}.run()

Attempts to use that flag:

$ swiftmatrix submit --nice 123
123.0

$ swiftmatrix submit --nice -123
An error occurred: Unexpected flag `-123` as a value for `--nice`

$ swiftmatrix submit --nice -0.123
An error occurred: Unexpected flag `-0.123` as a value for `--nice`

$ swiftmatrix submit --nice=-123
Unknown Arguments: --nice=-123

Options:
    --nice [default: 0.0]

$ swiftmatrix submit --nice=123
Unknown Arguments: --nice=123

Options:
    --nice [default: 0.0]
@kylef
Copy link
Owner

kylef commented Mar 25, 2022

I think supporting = would make the most sense, that would be consistent with other tools I've used in the past.

# valid
$ gateways list -f=-5m -t=now
$ gateways list --from=-5m --to=now

# not valid
$ gateways list -f -5m -t now
$ gateways list --from -5m --to now

kylef added a commit that referenced this issue Mar 26, 2022
kylef added a commit that referenced this issue Mar 26, 2022
@kylef
Copy link
Owner

kylef commented Mar 26, 2022

@rpendleton There are some changes in the repo with f22f0a0 and e1ba47e to support using equals with options and flags if you'd like to give that a go.

@rpendleton
Copy link
Author

Thanks. I finally got around to testing the changes in those two commits, and while I can confirm = can be used to specify arguments now, it seems it doesn't work for negative values.

Using the same code from my initial issue description:

$ swiftmatrix submit --nice 123
123.0

$ swiftmatrix submit --nice=123
123.0

$ swiftmatrix submit --nice=-123
An error occurred: Missing argument

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

No branches or pull requests

2 participants