-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Command.main() now calls exit() with returnvalue of invoke() #765
Conversation
click/core.py
Outdated
needs to be caught. | ||
whistles as a command line application. | ||
|
||
If *standalone_mode* is ``True`` (default), the application will |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
Please add a changelog entry and perhaps a |
click/core.py
Outdated
@@ -697,7 +704,7 @@ def main(self, args=None, prog_name=None, complete_var=None, | |||
rv = self.invoke(ctx) | |||
if not standalone_mode: | |||
return rv | |||
ctx.exit() | |||
ctx.exit(rv) |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
@untitaker Unfortunately the tests for chained commands still fail, I couldn't find out where to solve it yet. Could you take a look? |
Ok. Here's the problem:
If you run
You currently get It's much less obvious what to do here. Should we use the first non-zero, non-none value as exit code? Or...? |
Also it appears you can interrupt the chain by calling |
Thanks for taking a look. Imho, interrupting the chain and returning the last command's exit code makes the most sense. |
So if we |
TBH at this point I think this is too much of compatibility breakage to add, for very little benefit. |
No, on non-zero return, non-zero sys.exit() or any other exception. Just as if the command chain was invoked via the shell |
The thing is that sys.exit(0) breaks the chain already.
…On April 18, 2017 9:25:03 PM GMT+02:00, Niklas Rosenstein ***@***.***> wrote:
> So if we return 0 we should interrupt the chain?
No, on non-zero return, non-zero sys.exit() or any other exception.
Just as if the command chain was invoked via the shell `&&` operator,
like `cli foo && cli bar && cli baz`. I don't think that behaviour
would affect compatibility much. Alternatively, the `chain` parameter
could support an `||` and `&&` mode. Making `||` the default (and
mapping `chain=True` to `||`) would maintain full backwards
compatibility except for the change of the return value to only return
the result of the last command, which I deem a necessary and logical
change.
--
You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub:
#765 (comment)
--
Sent from my Android device with K-9 Mail. Please excuse my brevity.
|
You can catch it as |
Right, but at that point we would be breaking backwards compat because raising SystemExit already unconditionally interrupts the chain
…On April 19, 2017 7:43:14 AM GMT+02:00, Niklas Rosenstein ***@***.***> wrote:
You can catch it as `SystemExit` and check if the exit code is any of
`(0, None)` and dismiss it in that case if a nother command is to be
executed in the chain.
--
You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub:
#765 (comment)
--
Sent from my Android device with K-9 Mail. Please excuse my brevity.
|
I will close this because this behavior would be just too complex for the little value added. Sorry for noticing this problem so late. |
I might be missing your point or something but what's wrong with simply raising a Bringing this up 'cause nobody mentioned this here nor in #270 when it's already in my opinion a viable approach. Also functions' return values are already used for chained commands that relies on |
Your approach is entirely valid, but solves a different problem. This PR doesn't add new capabilities or enable a new usecase, it would've been a cosmetic change.
…On April 21, 2017 5:58:35 AM GMT+02:00, Kamekameha ***@***.***> wrote:
I might be missing your point or something but what's wrong with simply
raising a `ClickException` instance? Like you can look literally 4
lines bellow your change and see that `click` already catches
`ClickException` exceptions and exit the interpreter with the exit code
associated with the exception (i.e. with the `ClickException.exit_code`
attribute), so maybe you could subclass and customize said exception to
your needs and you could technically exit your CLI with virtually any
exit code.
Bringing this up 'cause nobody mentioned this here nor in #270 when
it's already in my opinion a viable approach. Also functions' return
values are already used for chained commands that relies on
`MultiCommand.resultcallback()` so basically any modification with
regards to commands' return values is already an API breakage for
`click` (see, for example,
http://click.pocoo.org/6/commands/#multi-command-pipelines).
--
You are receiving this because you modified the open/close state.
Reply to this email directly or view it on GitHub:
#765 (comment)
--
Sent from my Android device with K-9 Mail. Please excuse my brevity.
|
Oh, no no, my suggestion isn't trying to solve any problem at all, but neither is this PR. As you've noticed, this breaks chained multi-commands, and exit codes by function return value don't make that much sense for those either. How would you discern a valid return value of, for example, Just to be clear about my previous comment, what I meant is that return values on commands have already a documented behavior and design, and signaling errors is what I believe exceptions are for. To me, this looks more like a behavioral change rather than cosmetics. |
I agree with you, this is why I closed this PR.
…On Fri, Apr 21, 2017 at 07:09:38AM -0700, Kamekameha wrote:
Oh, no no, my suggestion isn't trying to solve any problem at all, but neither is this PR. As you've noticed, this breaks chained multi-commands, and exit codes by function return value don't make that much sense for those either. How would you discern a valid return value of, for example, `1` from an actual exit code?
Just to be clear about my previous comment, what I meant is that return values on commands have already a documented behavior and design, and signaling errors is what I believe exceptions are for. To me, this looks more like a behavioral change rather than cosmetics.
--
You are receiving this because you modified the open/close state.
Reply to this email directly or view it on GitHub:
#765 (comment)
|
return values are not handled by click, use ctx.exit instead, see why: pallets/click#765
see #270.
Testcase results are the same before and after the change (before, after).