-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
How can I reuse the function that iv made as a command? #330
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
Comments
I think when you make a function a command, that's it, it can only be used via the command line. Typically these functions will just do some minor CLI-related logic and then dispatch to a function that does the real work. So I would suggest moving any reusable logic into separate, regular functions so you can call them elsewhere. |
Thanks @nchammas |
I first used 'baker', then 'mando' for my command line interface helper, and both allow the same function to be used at the command line and via an API. This was nice to have. I would like to use 'click', because of other features, but this one missing feature I have come to rely on. Here is what I thought of:
Instead of being specified, the 'from_function_signature' would automatically create the parameter entries:
Is there any other work around? Is something like 3 a viable idea to be added to click? If so I may take a stab at making it happen. I also use *args and **kwds in a couple functions which might be difficult to handle. |
Option 1 is the only realistic one. Exposing your click function 1:1 is a very bad idea because those might rely on e.g. click closing files, click's special objects being passed etc. You can use the |
In 1. fashion, could may be click store and expose original decorated function, so for above example I could use something like Then it would be cool if it's |
Click does store and expose the original function: See #1054 for explanation |
Thank you @davidism !! |
It does not expose just the original function in |
|
i have the following code:
i made :init as my entry point and name it as MYCLI in setup,py
then i run MYCLI b print - i got console error:
if i remove the decorator above print_a, then everything will be fine.
Could anyone help? ... Why this is happening?
The text was updated successfully, but these errors were encountered: