Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Users can now write the content in the "create" method. #275
Users can now write the content in the "create" method. #275
Changes from 9 commits
697d16f
c4d488b
3e19405
01635de
a130bd6
9b8ecad
edc564f
d8a4257
a807a96
452011c
2ee34f4
1ada7bd
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you know the details of the various ways to exit a click program and which is best? (and why
:]
) I wasn't even aware thatctx.exit()
existed.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ctx.exit
means exit the program with code.You can always use the python
return
directive if you want, but it means that the exit code would be 0.Here, I chose to exit with code 1 because if the user did not write content, it means the operation has "failed", and the exit code should reflect that.
As for the use of
ctx.exit
, click has this real bad habit of wrapping built-in python methods with click functions (for example, wrapping theprint
method inclick.echo
). I don't like it at all, but I take it as a conversion when working with click (this is related to our mocking discussion). In our case, we could simply usesys.exit
instead and it would do the same.To sum up,
ctx.exit
is the best choice, considering that it is a convention.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree a non-zero exit code is sensible, my only question was how to do it. I asked about this in the Click discord and the only answer I got was
sys.exit()
, but I think they hadn't heard ofctx.exit()
either.:]
Anyways,click.echo()
does do more than print especially when dealing across Python versions and platforms. There's lots of room for major hassle when trying to handle that at the lower levels.