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

Investigate translation of CLI per-task args to Python types #69

Closed
bitprophet opened this issue Aug 19, 2011 · 3 comments
Closed

Investigate translation of CLI per-task args to Python types #69

bitprophet opened this issue Aug 19, 2011 · 3 comments

Comments

@bitprophet
Copy link
Member

Description

There is currently no nice way to specify "types" of input on the command-line -- everything is a string. This means that e.g.

$ fab mytask:some_bool_option=True

ends up as a Python function call like so:

mytask(some_bool_option="True")

instead of

mytask(some_bool_option=True)

which would be ideal.

See if there's any non-ugly way to make this better. I doubt there's anything perfect that doesn't involve something nasty one way or another -- nasty syntax or nasty bad-practices stuff like eval.

One idea that leaps to mind is to use "semi-magical" conventions, e.g.:

  • anything that looks like "true" or "false" (and/or "t/f", "yes/no", "y/n" etc etc) will get turned into the appropriate True/False value;
  • anything semicolon-separated turns into a list of strings;
  • anything fully numeric gets int-ified or float-ified;
  • etc.

This is less than ideal -- I don't like magic -- but it may have to be an acceptable sweet spot between "nope, can't do it, just parse your own strings" and e.g.

$ fab mytask:some_bool_option=bool:true,some_str_option=str:lolcats,some_list_option=list:"x;y;z"

which is just not appealing in the slightest.

Finally, we could keep the parsing as-is but provide the above conventions in Python userspace so users can do something like list_arg(arg) which is just shorthand for e.g. arg.split(';'). However, at that point we're still establishing conventions and then forcing users to do extra work anyways, which strikes me as kind of dumb.


Originally submitted by Jeff Forcier (bitprophet) on 2009-10-20 at 05:16pm EDT

Relations

@ghost ghost assigned bitprophet Aug 19, 2011
@bitprophet
Copy link
Member Author

Erich Heine (sophacles) posted:


Just a thought on this, perhaps a arg_types decorator, it feels ugly but also feels like the right starting point. Example:

@arg_types(BoolArg('x'), IntArg('y','z'))
def task(x, y, z):
     if x:
        do_something(y*z)
     else:
        do_other(y+z)

Where BoolArg and IntArg are validators, and arg_types inner decorator captures the args and kw. Essentially what Im suggesting is the same thing formencode validators do.


on 2010-02-05 at 11:09am EST

@bitprophet
Copy link
Member Author

Jeff Forcier (bitprophet) posted:


That's true, we could still do (yea, ugly) "static typing", but push it up to the task definition instead of leaving it on the command line as my earlier rant had mentioned. This makes more sense anyway, now that I think about it.

ALso, I'll link in that other ticket we were discussing today, since it is sticking around and these are related topics.


on 2010-02-05 at 11:33am EST

@bitprophet
Copy link
Member Author

pyinvoke/invoke#9

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

No branches or pull requests

1 participant