Is there a way to set default values?
Closed this issue · 3 comments
dhmspector commented
Maybe I am missing something, but is there a way to set default values that are then overridden by the command line? Trying to set the value of any of my options informs me it a get-only s property
jatoben commented
@dhmspector Typically you'd just catch the .value
nil case and set the default; something like this:
let cli = CommandLineKit.CommandLine()
let opt = StringOption(shortFlag: "o", longFlag: "option", helpMessage: "an option")
cli.addOption(opt)
do {
try cli.parse()
} catch {
cli.printUsage(error)
exit(EX_USAGE)
}
let o = opt.value ?? "default"
print("option is \(o)")
Does that work for you?
dhmspector commented
Yes, I see now. Different than I expected, but that'll work