Unfortunately, what you are trying to do does not make sense. Command line programs may have an exit code, but this is just a small integer; they cannot return text or arbitrary Python objects.
There is a quasistandard for which these integers mean; the simple version is 0 for success, 1 for most errors, 2 for invalid command line arguments. click tries to turn your function into a good command line user, so when you exit your function, it calls sys.exit with the corresponding number (0 if you return , 1 if you raise and 2 if it could not parse your arguments) .
So, regardless of the fact that you return has no effect, and everything you try to do with the return value at the top level does not even start.
What programs usually do when they need to "return" text is to print it to standard output, which is click.echo .
source share