I am trying to use click python package to pass a command line argument to a function. The example from official documentation works as explained. But nowhere in the documentati
Unfortunately, what you're trying to do doesn't make sense. Command-line programs can have an exit code, but that's just a small integer; they can't return text, or arbitrary Python objects.
There's a quasi-standard for what these integers means; the simple version is 0 for success, 1 for most errors, 2 for invalid command-line arguments. click
is trying to make your function into a good command-line citizen, so when you exit your function, it calls sys.exit
with the appropriate number (0 if you return
, 1 if you raise
, and 2 if it failed to parse your arguments).
So, whatever you return
has no effect, and whatever you try to do with the return value at the top level doesn't even get run.
What programs usually do when they need to "return" text is to print it to standard output, which is exactly what click.echo
is for.