thor: Returns exit 0 when a required argument is not provided
Simple example
#!/usr/bin/env ruby
require 'thor'
class Foo < Thor
desc "foo", ""
method_option :output, required: true
def foo
puts options[:output]
end
end
Foo.start
$ ./foo.rb foo -output=blah [1s]
No value provided for required options '--output'
$ echo $? [0s]
0
I’d expect this to return an error exit code
About this issue
- Original URL
- State: open
- Created 12 years ago
- Reactions: 16
- Comments: 28 (5 by maintainers)
Commits related to this issue
- Fix #6 Errors should cause a non-zero exit code. See https://github.com/erikhuda/thor/issues/244 — committed to jabley/gemfury by jabley 11 years ago
- Fix #6 Errors should cause a non-zero exit code. See https://github.com/erikhuda/thor/issues/244 — committed to jabley/gemfury by jabley 11 years ago
- Fix unexpected Thor exit status Related to https://github.com/erikhuda/thor/issues/244 — committed to laurilehmijoki/s3_website by laurilehmijoki 10 years ago
- hacky fix of https://github.com/erikhuda/thor/issues/244 — committed to haad/ops_build by deleted user 9 years ago
- Change default exit code bheavior to match norm fixes #244 — committed to dkniffin/thor by dkniffin 8 years ago
- Change default exit code behavior to match norm fixes #244 — committed to dkniffin/thor by dkniffin 8 years ago
- Merge pull request #578 from jmax315/master Fix incorrect use of Process::exit. This fixes open issue #244. — committed to rails/thor by rafaelfranca 6 years ago
- Ensure proper exit from error It appears that Thor does not allow exiting with an error code that is not 0, unless that is raised by Thor itself. There is some [description here][1]. I wish to be ab... — committed to futurelearn/drone-autoscale by surminus 6 years ago
- enable exit on failure refs: https://github.com/erikhuda/thor/issues/244 — committed to thaim/weekdone-cli-ruby by thaim 4 years ago
- CLI: Force thor to exit with a correct exit status Long-time issues on Thor related to exit status code cause msync to return a inappropriate exit code. As example: https://github.com/erikhuda/thor/... — committed to opus-codium/modulesync by neomilium 4 years ago
- CLI: Force thor to exit with a correct exit status Long-time issues on Thor related to exit status code cause msync to return a inappropriate exit code. As example: https://github.com/erikhuda/thor/... — committed to opus-codium/modulesync by neomilium 4 years ago
- CLI: Force thor to exit with a correct exit status Long-time issues on Thor related to exit status code cause msync to return a inappropriate exit code. As example: https://github.com/erikhuda/thor/... — committed to opus-codium/modulesync by neomilium 4 years ago
- CLI: Force thor to exit with a correct exit status Long-time issues on Thor related to exit status code cause msync to return a inappropriate exit code. As example: https://github.com/erikhuda/thor/... — committed to opus-codium/modulesync by neomilium 4 years ago
- CLI: Force thor to exit with a correct exit status Long-time issues on Thor related to exit status code cause msync to return a inappropriate exit code. As example: https://github.com/erikhuda/thor/... — committed to opus-codium/modulesync by neomilium 4 years ago
- nonzero exit on unexpected failure Old bad behavior now obtains warning, fix behavior and warning, see https://github.com/rails/thor/issues/244 — committed to licensee/licensee by mlinksva 2 years ago
Ok, so we bump the major version of Thor, and put it in the changelog. That’s what semantic versioning is for, right?
I raised a similar issue directly with Bundler, who’ve referred me here. It’s as simple as if you can’t do what I ask, don’t exit 0 – anything else is a bastardisation of 30 years of software sane practice.
https://github.com/carlhuda/bundler/pull/1892#issuecomment-15928663
It is indeed. The problem with Thor is that it’s never reached the 1.0 version, which is what SemVer defines as:
So, we have a version which is really defined for “initial development” even though it has been in widespread production usage for years. This is of course not optimal, but we must also remember and accept that when Thor was initially created, the SemVer specification as we know it today didn’t even exist. Things are a lot different now than they used to be back then.
Anyhow, I do agree with your point: we should work towards a 1.0 release of Thor, so we can start applying reasonable SemVer semantics to the releases etc.
My suggestion (this is mostly directed to @wycats or someone else working with the maintenance of this gem):
master
from 0.19.4 to 1.0.0 straight away, and publish it as a Rubygem. Make it a public announcement that the public API is now to be trusted.Hand raised ✋: I am willing to volunteer in this as needed, but is not currently a contributor or maintainer of this gem. If help/PRs are requested to get this moving, please let me and others know and we’ll do our best to contribute back to a very valuable Rubygem that means a lot to many of us.
Two thumbs up reacts and I’ll make a PR to stick this in the repo’s README.
@mohkale Currently if you run the program in the initial post of this ticket, you get a useful deprecation warning:
So this should get fully fixed in the next major release (I guess), and you can already opt-in to the right behaviour very easily.
i guess this will never get implemented, eventhough that is pretty critical?
The case https://github.com/erikhuda/thor/issues/244#issue-6116190 is still not working, even with adding
I guess the current, correct approach is similar to:
I think it just needs to be more clearly documented somewhere…