Skip to content

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

Closed
fancyremarker wants to merge 1 commit into
rails:masterfrom
fancyremarker:fix-hyphenated-value-parsing
Closed

Allow values to include hyphens when specified unambiguously with "="#498
fancyremarker wants to merge 1 commit into
rails:masterfrom
fancyremarker:fix-hyphenated-value-parsing

Conversation

@fancyremarker

Copy link
Copy Markdown

🌈

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.

# 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
Copy Markdown
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.

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
Copy Markdown
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
Copy Markdown
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