Skip to content

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

Description

@rpendleton

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]

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions