apple / apple/swift-argument-parser
ArgumentParser.ParserError.unknownOption(ArgumentParser.InputOrigin.Element.argumentIndex(2.0)
- Dominant language
- Swift
- Stars
- 3.8k
- Forks
- 411
- Avg merge
- 7d 14h
- Merged PRs (30d)
- 15
Description
Replace this paragraph with a short description of the incorrect incorrect behavior. If this is a regression, please note the last version that the behavior was correct in addition to your current version.
**ArgumentParser version:** `0.1.0` or the `main` branch, for example.
**Swift version:** Paste the output of `swift --version` here.
### Checklist
- [x] If possible, I've reproduced the issue using the `main` branch of this package
- [x] I've searched for [existing GitHub issues](https://github.com/apple/swift-argument-parser/issues)
### Steps to Reproduce
Using `main` branch v1.1.2. Here is how I'm implementing the code:-
```
import SwiftUI
import UserNotifications
import ArgumentParser
@main
struct NotificationAppApp: App {
@NSApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
@StateObject var model: ContentViewModel = {
let model = ContentViewModel()
do {
let parsedResult = try Notifier.parse()
parsedResult.update(model)
}
catch {
print("Error: Could not parse arguments")
print(CommandLine.arguments.dropFirst().joined(separator: " "))
print(Notifier.helpMessage())
print(error)
}
return model
}()
var body: some Scene {
WindowGroup {
ContentView(model: model)
}
}
}
struct Notifier: ParsableCommand {
static let configuration = CommandConfiguration(
abstract: "A Swift command-line tool to manage notificiations")
@Option(name: .shortAndLong, help: "The Message")
var message: String?
}
extension Notifier {
func update(_ viewModel: ContentViewModel) {
if let message = message {
viewModel.message = message
}
}
}
```
### Expected behavior
I'd expect it to parse the commandline arguments.
### Actual behavior
This is the error I'm getting:
```
CommandError(commandStack: [NotificationApp.Notifier], parserError: ArgumentParser.ParserError.unknownOption(ArgumentParser.InputOrigin.Element.argumentIndex(2.0), ArgumentParser.Name.short("N", allowingJoined: false)))
```
Contributor guide
Research direction
Start with the supplied Notifier declaration and reproduce the reported error using the main branch or v1.1.2, paying attention to the command-line arguments at argument index 2. Done means establishing a reproducible invocation and documenting why the reported short option is rejected.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- swift
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100