-
Notifications
You must be signed in to change notification settings - Fork 48
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
Single character flags #24
Conversation
@@ -40,6 +46,10 @@ extension RawArgument: Printable { | |||
|
|||
case let .Value(value): | |||
return "\"\(value)\"" | |||
|
|||
case let .Flag(flags): | |||
let combined = join("", map(flags) { String($0) }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can replace this whole expression with String(flags)
, because there's a constructor which accepts a SequenceType
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's much better.
This looks great, thanks! ✨
I want to agree so badly, but I feel like this kind of hampers composability. Many automated tools will append command line options blindly, expecting the last version of a given option to be the one that takes effect. I'd like to be able to integrate with tools like that, which means we should ideally honor the last option specified, whether it was the long or short form. |
I started looking at #3 last night and as part of that already have a fix for this. I ended up wrapping the key names in an enum of string or character or both. That allows the argument parser to consume them together and return the last thing it finds. |
Switches are now parameterless options that default to false and can't be disabled once enabled.
@jspahrsummers I addressed your main concern about compose-ability but in doing so I changed the semantics of This is less flexible than what I had before but it's consistent with the last writer wins behavior. Also it should be short-lived since I'm working on a mutually exclusive option set for #3. That'll allow long and/or short names for every choice. |
👍 Thanks @neilpa! |
Resolves #1. I plan to look at #3 as well but that depends on this change.
The one thing this doesn't handle perfectly is mixing short and long flags. It's biased to the last long form flag rather than the last of either. I expect this is probably fine though.