Skip to content

Add support for joined short options#240

Merged
natecook1000 merged 6 commits into
mainfrom
nate/join_us
Jan 16, 2021
Merged

Add support for joined short options#240
natecook1000 merged 6 commits into
mainfrom
nate/join_us

Conversation

@natecook1000
Copy link
Copy Markdown
Member

@natecook1000 natecook1000 commented Sep 17, 2020

Description

This supports joined arguments, like '-Ddebug' or '-v4'. Joined arguments need to be explicitly declared as .customShort("D", allowingJoined: true).

Detailed Design

You can now specify a Boolean allowingJoined value when declaring a custom short name specification, like this:

@main
struct Example: ParsableCommand {
    @Option(name: .customShort("D", allowingJoined: true))
    var debugValue: String

    func run() {
        print(debugValue)
    }
}

Existing calls still work as expected:

$ example -D debug
debug
$ example -D=debug
debug

And now you can use joined syntax:

$ example -Ddebug
debug

Documentation Plan

Expanded the documentation for .customShort(_:allowingJoined:) on both NameSpecification and NameSpecification.Element.

Test Plan

Unit tests covering the breadth of usage.

Source Impact

This is an additive change only, users must opt into the new functionality.

Checklist

  • I've added at least one test that validates that my change is working, if appropriate
  • I've followed the code style of the rest of the project
  • I've read the Contribution Guidelines
  • I've updated the documentation if necessary

@natecook1000 natecook1000 changed the title Add support for joined short options [WIP] Add support for joined short options Sep 17, 2020
@natecook1000 natecook1000 changed the base branch from master to main September 23, 2020 15:19
Copy link
Copy Markdown

@mpapple-swift mpapple-swift left a comment

Choose a reason for hiding this comment

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

Reviewed code; tested on Darwin. Looks good. Thanks for adding this enhancement @natecook1000.

@natecook1000 natecook1000 changed the title [WIP] Add support for joined short options Add support for joined short options Oct 24, 2020
This supports joined arguments, like '-Ddebug' or '-v4'. Joined arguments
need to be explicitly declared as `.customShort("D", allowingJoined: true)`.
@natecook1000
Copy link
Copy Markdown
Member Author

@swift-ci Please test

@natecook1000 natecook1000 merged commit 2a4664a into main Jan 16, 2021
@natecook1000 natecook1000 deleted the nate/join_us branch January 16, 2021 06:18
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.

3 participants