Giter Club home page Giter Club logo

Comments (4)

bitprophet avatar bitprophet commented on July 19, 2024

OK, found one reason for the current setup, dealing with ambiguity between otherwise valid flag-like things and positional args, e.g. if for some reason you wanted a positional arg to get the value --foo (and where --foo is also a valid flag in the same context).

However I'm unconvinced this is really a good idea so I'll try changing it.

from invoke.

bitprophet avatar bitprophet commented on July 19, 2024

Tried updating some tests to take this change into account (re: no longer requiring positionals=[]), but they aren't working quite right. Still poking.

from invoke.

bitprophet avatar bitprophet commented on July 19, 2024

So, beforehand, @task(positional=[]) meant none of the args got set positional. I'm trying to undo those and just set them to @task. Currently, this means anything with no default value becomes available as positional (but -- due to this ticket -- still works fine as a flag. win-win.)

Somehow, being positional means flags no longer get picked up as auto_shortflags. E.g.:

@task
def foo(bar, b):
    pass

bar does not get set to -a (which is what it would get set to as a shortflag because -b is already taken). I assume, but have not tested, that foo(an_arg, b) would similarly NOT alias an_arg to -a.

This needs to be fixed as many tasks assume auto_shortflags works.

from invoke.

bitprophet avatar bitprophet commented on July 19, 2024

Finally untangled things:

  • Shortflags were not getting made for positionals because there was still a "don't do this for positional args" test in the shortflags block. Oops.
  • When that was fixed, shortflags no longer got set the way tests expected, because positionals get sent to the front of the list before shortflags get created (and thus take precedence).
  • When that was fixed, other tests ensuring that when positional args are in fact given positionally and not as flags, the order matches what was given in @task(positional=[x, y, z]), failed, because positional order was lost.
  • Finally, decided to preserve that ordering (which has to be communicated from Task to Context) by preserving the "make sure positionals come first" logic but applying it after creation of Argument objects and thus shortflags.

This has gotten all tests passing, though I am still with doubts about the overall positional API. E.g. I had to add @task(positionals=[]) to one test to ensure that one of the args with no default value still didn't get taken as a positional -- because positionals are still required if not given as a flag. It just feels kind of messy and easy to find pitfalls in.

Also, "I have an empty list for positionals" may be a correct or easy way of turning auto-positionals off for a given task, but it is also ugly. Make sure that if that doesn't fall under the purview of other issues, one is made.

from invoke.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.