You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
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.
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.
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.
ends up as a Python function call like so:
instead of
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.:
True
/False
value;int
-ified orfloat
-ified;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.
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
The text was updated successfully, but these errors were encountered: