apple / apple/swift-argument-parser

Support passing a negative number as an argument

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

Description

Imagine a command like this

```swift
import ArgumentParser

struct Absolute: ParsableCommand {

@Argument() var number: Int

func run() throws {
print(abs(number))
}
}

Absolute.main()
```

you can run

```
command 5
```

and it works. but running

```
command -5
```

fails with `Error: Missing expected argument ''` which makes sense.

I would have expected being able to pass the argument as `"-5"` but that doesn't work either.

Any advice on how to handle this?

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the Absolute.main example with @Argument() var number: Int, comparing command 5 with command -5 and the quoted form. Trace how positional Int arguments handle option-like tokens; done means negative values are accepted while normal option parsing and existing argument behavior remain intact.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
cli
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.