Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'--help' and '--version' options returns exit status 1. #28

Merged
merged 5 commits into from Mar 28, 2017
Merged

'--help' and '--version' options returns exit status 1. #28

merged 5 commits into from Mar 28, 2017

Conversation

FGtatsuro
Copy link
Contributor

Now, {command} --help and {command} --version returns exit status 1. For example,

$ ./bin/packer --help
...
$ echo $?
1
$ ./bin/packer --version
0.8.7
$ echo $?
1

These are normal cases, thus exit status 0 is better I think.
This PR changes the behavior as follows.

$ ./bin/packer --help
...
$ echo $?
0
$ ./bin/packer --version
0.8.7
$ echo $?
0

Could you check it?

@sethvargo
Copy link
Contributor

Hey @FGtatsuro

I tested a bunch of different UNIX tools and the behavior is rather inconsistent. Some exit 0, some exit 1, some exit 127. Even more, some print to stderr and some print to stdout. I think this change is probably fine, since I don't imagine anyone depending on the exit status of -v or -h that this would introduce a breaking change, but I defer to @mitchellh.

@cbednarski
Copy link

Updating here since this is a common complaint in packer.

The -v behavior is also internally inconsistent since our tools also have a version command which (as far as I tested) exit 0. I think it would be good to have well-defined behavior here:

  1. [program] version, [program] -v, and [program] --version all exit 0
  2. version is always printed on stdout

This facilitates writing bash scripts which check whether the program is present before continuing.

Help is a bit more nuanced. Help is usually displayed when a program is run incorrectly (i.e. without required arguments). In the default case help output should exit 1. If help is called explicitly it should exit 0. go, git, curl, brew and other tools are pretty consistent in this behavior.

@mitchellh
Copy link
Owner

Given the inconsistency I'm down with making the behavior go to exit code zero. That was my expectation years ago and made the same logical conclusion in the previous sentence for keeping it as 1, too. Changing it now.

@mitchellh mitchellh merged commit 4611adf into mitchellh:master Mar 28, 2017
@FGtatsuro FGtatsuro deleted the exitstatus branch March 28, 2017 06:41
@FGtatsuro
Copy link
Contributor Author

@mitchellh
Thank you for your action!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants