-
Notifications
You must be signed in to change notification settings - Fork 367
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
List-type arg values #132
Comments
I'm strictly opposed to the
) Other than that, I have a preference towards the |
I also prefer the repeating arguments way, or the argparse/optparse way, to handle list. It's more intuitive to work with from viewpoint of commandline. Just wondering how you would like to handle this then. |
@sophacles Yea that was just a dumb example, if I did go the "sub-parsing" route I'd probably use commas (again) as it's one of the few without common shell meaning. But it sounds like going for correctness ( |
@bitprophet Just wondering how would you like to do this. I am willing to provide any help, even though some code snippets as long as you're comfortable with that. |
@drakeguan I'll take care of it sometime soon, have been on vacation until today. |
Really excited to know that. Just let us (I believe there are lots developers interested in this feature) know if there is anything need help or discussion, then. Thank you! |
(3 years later...) I've got a POC of this for the base case (list of strings) working, where one manually indicates which arguments should be list-type instead of string-type - similar to how positional and optional args are configured. E.g.:
and then:
Need to backfill more tests & figure out some of the corner/edge cases:
|
That base case is all doc'd up now. Wondering if I can cram in the
|
One worry about going the direct-argument-link route is it makes me want to fold the existing Also, as I glance at how this would work, there's a bigger issue - Probably better is the idea I had earlier which was for this mapping to just be "arg args", i.e. kwargs to be given to the @task(arg_kwargs={'mylist': {'kind': list}})
def mytask(c, mylist):
pass Downside is that there's no good name for this due to the clash between parser/cli "args" and function/class "args/kwargs". Blah. This may be something that only gets fully developed under Python 3 since it now allows for actual type annotations (including, I believe, lists-of-kinds e.g. |
Anyway that stuff all really belongs in #174 / #378 as noted earlier. For now, I think I am gonna go with the |
Naming of that arg still problematic since the current ones are all "these arguments are ", i.e. "these arguments are |
That's what it ended up being. This is done! It's kinda first-draft:
But it definitely works for me as documented and tackles both of the related use cases, so, hooray! |
Strongly related to #9, how to handle list values.
In #9, I assumed they would be contiguous values on the CLI with a separator, e.g.
inv mytask --listarg list;val;here
.However, a common pattern for existing arg parsing libs is to give a flag >1 time and have the results tallied into a list, e.g.
inv mytask -l list -l val -l here
. E.g. this is how argparse/optparse do it, IIRC.Pros of that latter approach:
Cons:
-l here
"winning" as a string, not list, value. Some users may expect or desire this behavior, e.g. when stitching together args from various "levels" of an invoking program.mytask --listarg a;b;c
is much faster thanmytask -l a -l b -l c
.Either way:
mytask --listarg 1,2,3
into a list of ints automatically? Which again ties back into CLI arg typecasting #9.The text was updated successfully, but these errors were encountered: