Comments (4)
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.
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.
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.
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
toContext
) 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)
- Change default shell without a config file or Context? HOT 3
- Task decorator removes docstring HOT 1
- Run tasks relative to `tasks.py` HOT 2
- How to manually set short flags? HOT 1
- context.run(): Expose API to pass command and separate args instead of a single string HOT 2
- Specify a config file per Collection... possible?
- Collection mix-up when cross importing invoke tasks
- Running post tasks even if the main task fail
- `--help` after the command treats `--help` as positional argument HOT 2
- Is there support for making invoke.yaml context settings cli flags?
- EncodeWarning's when running on python >= 3.11
- @task(pre=[call(setup, 'qwe')]) fails with "NameError: name 'call' is not defined" HOT 1
- Config run should handle shell paths with spaces HOT 2
- Is it possible to only mock one command and run the rest with MockContext?
- autoprint generators correctly
- Generate help infomation of task args from function docstring.
- Importing Python modules from a scripts directory beside the tasks directory
- Recommended way to forward arguments to commands HOT 2
- Printing Promise objects from asynchronous Runner.run() raises Attribute Error
- Sudo showing password in clear
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from invoke.