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

Parse() calls os.Exit(0) in case of parse error #22

Closed
marco-m opened this issue Jun 29, 2019 · 3 comments
Closed

Parse() calls os.Exit(0) in case of parse error #22

marco-m opened this issue Jun 29, 2019 · 3 comments

Comments

@marco-m
Copy link

marco-m commented Jun 29, 2019

Hello,

I guess this is a design choice, but I would like the opposite, is there a way?

  • Parse() exits with 1 in case of parse error related to argument (this I like)
  • Parse() exits with 0 in case of parse error related to options (this I would like to change)

I would like:

  • Parse() to always exit with a non-zero exit code in case of parse error.
  • Even better I would like Parse() (or another function) not to exit behind my back and return a classic Go tuple with an error.

Rationale: any UNIX/POSIX command-line utility exits with non-zero in case of user calling it incorrectly.

Example with cp on macOS:

> cp a b ; echo $status
cp: a: No such file or directory
1
> cp ; echo $status
usage: cp [-R [-H | -L | -P]] [-fi | -n] [-apvXc] source_file target_file
       cp [-R [-H | -L | -P]] [-fi | -n] [-apvXc] source_file ... target_directory
64
> cp -x; echo $status
cp: illegal option -- x
usage: cp [-R [-H | -L | -P]] [-fi | -n] [-apvXc] source_file target_file
       cp [-R [-H | -L | -P]] [-fi | -n] [-apvXc] source_file ... target_directory
64

What are my options with opts ? Would you consider a PR ? Thanks!

@marco-m marco-m changed the title Parse() calls os.Eexit(0) in case of parse error Parse() calls os.Exit(0) in case of parse error Jun 29, 2019
@marco-m
Copy link
Author

marco-m commented May 24, 2020

Hello @jpillora friendly ping :-)

@jpillora
Copy link
Owner

Oh yes, should indeed exit with 1, PR 😁 ?

@marco-m
Copy link
Author

marco-m commented Jun 8, 2020

thanks!

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

No branches or pull requests

2 participants