Skip to content
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

Allow client to specify declaration order for parameter-handling precedence #730

Open
senderista opened this issue Feb 10, 2017 · 2 comments

Comments

@senderista
Copy link

Since Click changed its parameter-handling precedence to invocation order rather than declaration order, I've had to apply hideous hacks to force declaration-order precedence. To be clear, I have absolutely no use for invocation-order precedence, and I need completely fine-grained control over parameter precedence (I have a couple dozen options to one of my CLI commands, with tricky dependencies). I'll have to fork Click to work around this if there's no supported way to force declaration-order precedence.

@potens1
Copy link

potens1 commented Feb 14, 2017

Same here, little use case: my script need to have db host in option and dbname, objects name are given as parameters, the callback to validate the objects name needs to know the db host and the dbname, dbname is prompted if not given. If I run it without args, the parameters validator is run before the dbname one, if I put the dbname as eager, then, it is run even if I only want the help.
So it could be great if you can say, my first arg is always that, the second one is that, and so on. (maybe there could be a way to give some dependencies in callbacks, to say, do this one before that one...)

@senderista
Copy link
Author

Exposing this option should be trivial; my fix to force declaration order was one line:

diff --git a/click/core.py b/click/core.py
index 18c1766..78fda17 100644
--- a/click/core.py
+++ b/click/core.py
@@ -878,8 +878,9 @@ class Command(BaseCommand):
         parser = self.make_parser(ctx)
         opts, args, param_order = parser.parse_args(args=args)

-        for param in iter_params_for_processing(
-                param_order, self.get_params(ctx)):
+        for param in self.get_params(ctx):
             value, args = param.handle_parse_result(ctx, opts, args)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants