pyinvoke / invoke

Pythonic task management & command execution.
http://pyinvoke.org
BSD 2-Clause "Simplified" License
4.4k stars 367 forks source link

optional positional argument #159

Open adrianandreias opened 10 years ago

adrianandreias commented 10 years ago

If I understand correctly (based on http://invoke.readthedocs.org/en/latest/api/tasks.html#invoke.tasks.task) optional AND positional arguments are not available (at the same time).

Any combination I tried I didn't manage to get both of these lines working:

invoke build
invoke build /path/target.tar.gz
@target
def build(target='default.tar.gz'):
    print target

I think only optional arguments that are not positional work:

invoke build --target=/path/target.tar.gz

Is there a way to achieve this? Or can you consider this feature request?

Thanks

bitprophet commented 10 years ago

Yes, this looks like a gap in feature coverage, thanks for bringing it up!

I'll need to think about whether it's worth adding but offhand I can't think of a great reason not to, unless it makes the parser that much more complicated.

sophacles commented 10 years ago

:+1: It should be noted that this is related to #167 in that it involves how argument parsing is done.

bitprophet commented 10 years ago

@sophacles is it really? There's a lot of parsing tickets out there and I don't see how these two overlap :)

sophacles commented 10 years ago

@bitprophet Just thinking in breaking corner cases, mostly when arg values and task names overlap, and the positional args are optional.. With further "reporting the problem" complications in error messages.

@task
def foo(bar, baz="default_baz"):
    do_something(bar, baz)

def thing(stuff="default-stuff"):
    do_something_else(stuff)

How do we handle?

# is the literal "thing" here a task name or the second arg to foo?
$ inv foo bar_arg thing "stuff_arg"

#what if I want to pass a literal thing as the second arg to foo... ala:
$ inv foo bar_arg "thing" thing

# note the quotes above don't really fix what is given to argv
# also note, it gets even wierder with required args.

# with repetition of a tasks
$ inv thing thing thing
# or even more fun if we declar the second arg to bar as positional and required...
# how do we report this error... (I'm guessing right now it's "No idea what "stuff" is!")
$ inv bar "stuff" thing "stuff" thing "stuff"
aidanlister commented 8 years ago

Do we need to support multiple tasks on the same invocation?

I've been using fabtools for a long time so fab foo bar was pretty great, but invoke has already done away with the terse syntax ... inv foo && inv bar isn't so much worse and it'd drop a lot of weirdness?

bitprophet commented 7 years ago

Definitely have my own use case(s) for this now, adjusting metadata accordingly :D