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

[WIP] Add ArgumentSource as the projected value of arguments #128

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

natecook1000
Copy link
Member

@natecook1000 natecook1000 commented May 2, 2020

Description

This adds a new ArgumentSource type as the projected value for @Argument, @Option, and @Flag types. This way, you can access the original string and location in the command-line arguments that produced a value.

struct Example: ParsableCommand {
    @Argument()
    var name: String

    @Option()
    var age: Int

    func run() {
        print("Your name is \(name) and your age is \(age).")
        if $name.source.first!.position < $age.source.first!.position {
            print("You gave your name before your age.")
        } else {
            print("You gave your age before your name.")
        }
    }
}
$ example --age 43 Blake
Your name is Blake and your age is 43.
You gave your age before your name.

Detailed Design

TK

Documentation Plan

TK

Test Plan

TK

Source Impact

This would be an additive change only.

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

@kylemacomber
Copy link
Contributor

Neat idea!

@mpapple-swift
Copy link

Looks good, @natecook1000! Thanks for adding this.

@MPLew-is MPLew-is mentioned this pull request Jun 22, 2020
4 tasks
@natecook1000 natecook1000 changed the base branch from master to main September 24, 2020 23: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.

None yet

3 participants