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

More consistent API #42

Closed
wants to merge 5 commits into from
Closed

More consistent API #42

wants to merge 5 commits into from

Conversation

djbe
Copy link
Collaborator

@djbe djbe commented Dec 1, 2016

@@ -239,4 +239,26 @@ public final class ArgumentParser : ArgumentConvertible, CustomStringConvertible

return nil
}

/// Returns the value for an option (--name Kyle, --name=Kyle) or flag (-n Kyle)
public func shiftValueForOption(_ name: String, orFlag flag: Character?) throws -> String? {
Copy link
Owner

Choose a reason for hiding this comment

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

I'm not sure if I like this function name (with orFlag), although I don't have any better ideas at the moment.

Gonna have a think about this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Suggestion: make 2 type aliases:

typealias Option = String
typealias Flag = Character

and rename the method to:

shiftValue(for name: Option, or flag: Flag?)

@@ -18,7 +18,7 @@ public func testArgumentDescription() {
let help = Help([
BoxedArgumentDescriptor(value: Option<String>("opt1", "example")),
BoxedArgumentDescriptor(value: Flag("flag1", description: "an example")),
BoxedArgumentDescriptor(value: Flag("flag2", default: true)),
Copy link
Owner

Choose a reason for hiding this comment

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

I think I prefer the label being explicit here. It's clearer to the reader what the value true is actually for.

Perhaps it would make more sense to make the default label explicit on all options. The reason it wasn't initially there for Option is because option MUST have a default value.

@@ -242,7 +242,7 @@ public func command<A:ArgumentDescriptor, A1:ArgumentDescriptor, A2:ArgumentDesc
BoxedArgumentDescriptor(value: descriptor5),
])

if parser.hasOption("help") {
if parser.has(option: "help") {
Copy link
Owner

Choose a reason for hiding this comment

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

I'm not certain, but I think this might be discourage from the Swift API guidelines.

https://swift.org/documentation/api-design-guidelines/#argument-labels

screen shot 2016-12-12 at 16 59 34

Copy link
Collaborator Author

@djbe djbe Dec 12, 2016

Choose a reason for hiding this comment

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

I first removed those, but then the compiler gets confused and I had to add a bunch of typecasts.

You get:

  public func has(_ name: Option) -> Bool {}
  public func has(_ flag: Flag) -> Bool {}

If I then call parser.has("a"), swift will get confused because "a" is a string. This has mostly to do with the unit tests.

Do you mean going back to this?

  public func hasOption(_ name: Option) -> Bool {}
  public func hasFlag(_ flag: Flag) -> Bool {}

@kylef
Copy link
Owner

kylef commented Feb 21, 2017

I think this PR is almost good to go, just one last thing. We will need to update the examples in the README https://github.com/kylef/Commander#describing-arguments

Option("count", 1, description: "The number of times to print.")

djbe added 5 commits February 21, 2017 23:36
- All Option-related types have a validator.
- All Option-related types have a flag parameter.
- All constructors have the same init-parameters order.
@kylef
Copy link
Owner

kylef commented Oct 8, 2017

I've rebased this merged this into master. 🍰

@kylef kylef closed this Oct 8, 2017
@djbe djbe deleted the feature/consolidate-argument-description branch October 8, 2017 21:54
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