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

Exit code from educate #57

Closed
jaredbeck opened this issue May 9, 2015 · 6 comments · Fixed by #63
Closed

Exit code from educate #57

jaredbeck opened this issue May 9, 2015 · 6 comments · Fixed by #63

Comments

@jaredbeck
Copy link

Trollop.educate exits with code 0. I would like to use Trollop in an existing script, but usage errors must exit with a code N != 0. As a workaround, I can reopen Trollop:

module Trollop
  def self.educate_without_exiting
    @last_parser.educate
  end
end

# somewhere in my code
Trollop.educate_without_exiting
exit(N)

Is there a better way for me to exit with a code N of my choosing?

PS: I'm using Trollop for the first time and I really like it so far. Thanks for the lib!

@kbrock
Copy link
Member

kbrock commented May 9, 2015

At first I totally agreed, now I'm mixed on this one.

If you specify --help on the command line, are you expecting a non 0 return status?

In your example, is help coming from a misuse, or an error?

@jaredbeck
Copy link
Author

If you specify --help on the command line, are you expecting a non 0 return status?

Good point. If I'm requesting --help, I'd expect 0.

In your example, is help coming from a misuse, or an error?

Misuse, i.e. any time the usage is printed except for when --help is requested.

@kbrock
Copy link
Member

kbrock commented May 10, 2015

@jaredbeck do you have a test case (not formally)

4 liner parse and opt blurb with a description of what you pass in on the command line and when you expect to get errors?

I can convert into an official test, just want to make sure I am coding up your case.

--Keenan

@jaredbeck
Copy link
Author

Sure, let me see what I can come up with. What if we consider cp? It takes a variety of options and (usually) two arguments, a source path and a target path. When only one argument is given, it prints usage and exits with a specific non-zero code.

It's my understanding that trollop is responsible only for options. After parsing options, only the arguments are left in ARGV, right? So, if we were implementing cp, we'd check the length of the remaining arguments. If there were only one argument, we'd print usage and exit with that specific code.

Is that a good example? Do you want me to take the next step and write an opt blurb for it?

@kbrock
Copy link
Member

kbrock commented May 10, 2015

@jaredbeck No code needed. I had misunderstood you. pr 58 helped a lot.
I have what I consider a good fix, but am in the middle of a refactor in the test area.

If I don't merge in a fix for your issue by next friday, please ping me to keep me honest.

@kbrock
Copy link
Member

kbrock commented May 16, 2015

After I get #61 in, I'll tack this on

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 a pull request may close this issue.

2 participants