apple / apple/swift-argument-parser

Add a .implicit name specification, for @Option initializers

Open
#99 2 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Swift
Stars
3.8k
Forks
411
Avg merge
7d 13h
Merged PRs (30d)
17

Description

Properties wrapped by ``@Option`` with a ``.implicit`` name specification would be handled like those with ``@Argument`` and would allow command line tools like this one (inspired from sed).

```swift
import ArgumentParser

struct MySed: ParsableCommand {

// my-sed 's/hello/world/' input.txt
// my-sed -e 's/hello/world/' input.txt
// my-sed --expression='s/hello/world/' input.txt

@Option(name: [.implicit, .short, .long])
var expression: [String]

@Argument()
var input: [String]

func run() throws {
print("expression: \(expression)")
print("input: \(input)")
}

}

MySed.main()
```

Help would show properties wrapped by ``@Option`` with an ``.implicit`` name specification into brackets
```
[[--expression] ]
```

They would, like ``@Argument``, be order dependent and face identical limitations when used on array properties.

Only one ``.implicit`` would be allowed by property (even on array properties)... in order to let simple in/out command line tools like

```
inout [-i] [-o]
```
process two files without ambiguity.

Contributor guide

Open the contributing guide

Research direction

Start by locating how @Option name specifications are handled, then compare that behavior with @Argument for ordering, array limitations, and help rendering. Use the sed-style examples as the acceptance criteria; done means .implicit options support the documented forms and restrictions without ambiguity.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
cli
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.