-
Notifications
You must be signed in to change notification settings - Fork 1
Description
Hello,
when you use a callback parser, there is no other way of stopping parsing the command line arguments than to call os.Exit(). This is inconvenient if you need to do some clean up when you detect that parsing the command line arguments was not successful.
I would like to suggest modifying the signature of the callback parser so that it returns for instance a bool to tell go-options that the parsing process can continue or not.
In the return value of spec.Parse() we would need a way to know if the parsing ended successfully or not. For instance:
spec := options.NewOptions(mySpec).SetParseCallback(MyParseCallback)
opt := spec.Parse(os.Args[1:])
if ! opt.ParsingWasOK() {
// Do some cleanup here
}
In the current situation, we have to call the cleanup process in every 'case' of the 'switch' of the parse callback. If your command accepts several options, this may be a lot of code to repeat.
Best regards,