I'm trying to read in a ParsableCommand into a App to then post a Notification on macOS, but I'm running into an error when the app is trying to parse the CommandLine arguments.
Using Xcode 13.3.1. App deployment target is 12.3.
This is the error I get:
CommandError(commandStack: [NotificationApp.Notifier], parserError: ArgumentParser.ParserError.unknownOption(ArgumentParser.InputOrigin.Element.argumentIndex(2.0), ArgumentParser.Name.short("N", allowingJoined: false)))
Here is 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
}
}
}