Skip to content

Conversation

@glessard
Copy link
Contributor

@glessard glessard commented Mar 3, 2020

This is an attempt to fix #49

Questions about this proposed fix:

  • Would it be better to simply extract the strings at the point where the error is thrown?
    I touched every place where "duplicateExclusiveValues" appears, so it's not clear that error case would have another use than this one.
  • Is the proposed replacement message any good?

@glessard glessard force-pushed the duplicative-flags branch from 32d5370 to 6477202 Compare March 3, 2020 18:01
@glessard
Copy link
Contributor Author

glessard commented Mar 3, 2020

This conflicts with the changes in #21, where the internals of InputOrigin were closed off.

(specifically, I used the getter for var elements: [Element])

Copy link
Member

@natecook1000 natecook1000 left a comment

Choose a reason for hiding this comment

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

Looking good! Just a couple small requests.

func testDuplicateFlags() {
AssertErrorMessage(Options.self, ["--list", "--bool", "-s"], "Value to be set with flag \"-s\" had already been set with flag \"--list\"")
AssertErrorMessage(Options.self, ["-cbl"], "Value to be set with flag \"l\" in \"-cbl\" had already been set with flag \"c\" in \"-cbl\"")
AssertErrorMessage(Options.self, ["-bc", "--stats", "-l"], "Value to be set with flag \"--stats\" had already been set with flag \"c\" in \"-bc\"")
Copy link
Member

Choose a reason for hiding this comment

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

Nice work, these are great messages!

func duplicateExclusiveValues(previous: InputOrigin, duplicate: InputOrigin, arguments: [String]) -> String? {
func elementString(_ origin: InputOrigin, _ arguments: [String]) -> String? {
guard case .argumentIndex(let split) = origin.elements.first else { return nil }
var argument = "\"\(arguments[split.inputIndex.rawValue])\""
Copy link
Member

Choose a reason for hiding this comment

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

We're using single quotes around user input in the other messages, can you do the same here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had failed to notice. Done!

return "flag \(argument)"
}

let dupeString = elementString(duplicate, arguments) ?? "position \(duplicate)"
Copy link
Member

Choose a reason for hiding this comment

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

Can you add to-do comment here to about updating this when we support environment values? It's worth noting that the RHS of these coalescing operators won't ever get hit.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@glessard glessard force-pushed the duplicative-flags branch from af08a46 to 4eccca6 Compare March 3, 2020 21:53
@glessard
Copy link
Contributor Author

glessard commented Mar 3, 2020

I reinstated some of what had been removed in 6b3a0a1, because it was what I'd used to peek in and extract the necessary info. If there's another method, I can use that, but I haven't seen it.

@glessard glessard force-pushed the duplicative-flags branch from 4eccca6 to 7c642ec Compare March 3, 2020 22:09
@glessard glessard requested a review from natecook1000 March 4, 2020 01:00
Copy link
Member

@natecook1000 natecook1000 left a comment

Choose a reason for hiding this comment

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

🚢

@natecook1000 natecook1000 merged commit 53a00f5 into apple:master Mar 4, 2020
@glessard glessard deleted the duplicative-flags branch March 4, 2020 18:25
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.

Unhelpful error output when using two mutually exclusive flags

2 participants