Skip to content

Callback parser should not need to stop parsing by calling os.Exit #4

@airnandez

Description

@airnandez

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,

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions