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

Single character flags #24

Merged
merged 10 commits into from
Apr 6, 2015
Merged

Single character flags #24

merged 10 commits into from
Apr 6, 2015

Conversation

neilpa
Copy link
Member

@neilpa neilpa commented Apr 1, 2015

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.

@jspahrsummers jspahrsummers self-assigned this Apr 2, 2015
@@ -40,6 +46,10 @@ extension RawArgument: Printable {

case let .Value(value):
return "\"\(value)\""

case let .Flag(flags):
let combined = join("", map(flags) { String($0) })
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 you can replace this whole expression with String(flags), because there's a constructor which accepts a SequenceType.

Copy link
Member Author

Choose a reason for hiding this comment

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

That's much better.

@jspahrsummers
Copy link
Member

This looks great, thanks! ✨

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.

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.

@neilpa
Copy link
Member Author

neilpa commented Apr 3, 2015

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.

neilpa added 3 commits April 2, 2015 20:05
Switches are now parameterless options that default to false and can't
be disabled once enabled.
@neilpa
Copy link
Member Author

neilpa commented Apr 3, 2015

@jspahrsummers I addressed your main concern about compose-ability but in doing so I changed the semantics of Switch. Now it's a parameterless option that defaults to false. Once enabled it can't be disabled again. Boolean toggles will need to still use Option<Bool> without the single letter support.

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.

@jspahrsummers
Copy link
Member

👍 Thanks @neilpa!

jspahrsummers added a commit that referenced this pull request Apr 6, 2015
@jspahrsummers jspahrsummers merged commit b470b6e into Carthage:master Apr 6, 2015
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.

Support single-character flags
2 participants