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

Allow values to include hyphens when specified unambiguously with "=" #498

Closed

Conversation

fancyremarker
Copy link

🌈

I noticed that if an option value begins with a "-" (/^-/), it will be parsed as a switch, even in cases like

--foo=-bar

where it seems that the presence of the "=" allows the value (-bar) to be unambiguously parsed as a value instead of a switch.

The new spec expectation should be clear; I'm less confident in the implementation, as the current implementation relies quite a bit on several stateful instance variables.

@@ -129,6 +134,7 @@ def check_unknown!
# Two booleans are returned. The first is true if the current value
# starts with a hyphen; the second is true if it is a registered switch.
def current_is_switch?
return false if @force_value
Copy link
Member

Choose a reason for hiding this comment

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

This should return an array.

@@ -257,6 +257,7 @@ def remaining
expect(parse("-f=12")["foo"]).to eq("12")
expect(parse("--foo=12")["foo"]).to eq("12")
expect(parse("--foo=bar=baz")["foo"]).to eq("bar=baz")
expect(parse("--foo=-bar")["foo"]).to eq("-bar")
Copy link
Member

Choose a reason for hiding this comment

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

We need a test when there is more than one options.

when EQ_RE
unshift($2)
switch = $1
@force_value = true
Copy link
Member

Choose a reason for hiding this comment

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

I think setting this state here will broke it if there are more options after the first with - in the value, can you add tests to make sure it will work?

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.

2 participants