Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Feb 24, 2020. It is now read-only.

Conversation

@marineam
Copy link
Contributor

@marineam marineam commented Feb 8, 2016

An obsolete CoreOS test was erroneously passing:

Error: unknown command "install" for "rkt"
Run 'rkt --help' for usage.
2016-02-08T00:57:26Z kola: --- PASS: coreos.rkt.install

An obsolete CoreOS test was erroneously passing:

    Error: unknown command "install" for "rkt"
    Run 'rkt --help' for usage.
    2016-02-08T00:57:26Z kola: --- PASS: coreos.rkt.install
@iaguis
Copy link
Member

iaguis commented Feb 8, 2016

LGTM

// os.Exit(0)

cmdRkt.Execute()
if err := cmdRkt.Execute(); err != nil && cmdExitCode == 0 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there something more specific we can check error against? might there not be false positives here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also really it would be nice to handle all non-nil errors (I know we were previously just ignoring but since you're going part of the way there..)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to do anything with the error since cobra will have already logged it. As far as I can tell any errors indicate that cobra did not execute a command so there isn't any false positives. As such the check for cmdExitCode == 0 is probably not needed but I included it just in case there was ever a code path where cmdExitCode got set to some other code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One improvement that this points out is that it would be nice if cobra itself had an option to abort the program itself on errors. Also it is weird that cobra returns a nil error if there is no runnable command (e.g. running rkt without any arguments), internally it treats rkt and rkt help as identical commands despite the first being a usage error and the second being valid.

@alban alban added this to the v1.1.0 milestone Feb 9, 2016
@marineam
Copy link
Contributor Author

marineam commented Feb 9, 2016

If you want to be more explicit about behavior and not depend on cobra logging errors and dumping usage we can handle that explicitly and set cmd.SilenceErrors and cmd.SilenceUsage

@iaguis
Copy link
Member

iaguis commented Feb 19, 2016

I think it's fine the way it is now. @jonboulle?

@jonboulle
Copy link
Contributor

no strong feelings, do what you think is best

iaguis added a commit that referenced this pull request Feb 23, 2016
rkt: use exit status 2 to report usage errors
@iaguis iaguis merged commit 9003f4a into rkt:master Feb 23, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants