pydoit / doit

CLI task management & automation tool
http://pydoit.org
MIT License
1.84k stars 175 forks source link

Allow `list` to be used in `default_tasks` #421

Open mathbunnyru opened 2 years ago

mathbunnyru commented 2 years ago

Right now, default_tasks should contain tasks from the dodo.py configuration. Sometimes, there are projects, which do not have a good default. If would be nice to have "default_tasks": ["list"], so when I type doit, I get a nice description of available commands.

Describe alternatives you've considered

Fund with Polar

schettino72 commented 2 years ago

doit has the concept of "commands" and "tasks". list is a "command", so not suitable to be used as default_tasks

The default command is run. That allows you you to write doit my_task without having to explicitly specify the command as doit run my_task.

Simply switching the default command to list would not work well as doit my_task would simply use the list command and just "list" the task. But I guess it could be easily special-case doit without any parameters to execute list while any other parameter/option would switch back to have run as default.

I have seen people define the "default" task just to print a help message, like Use "doit list" to see available tasks ordoit helpfor available commands.

I do not think it is worth the trouble to implement what you are suggesting... But if anyone is willing to work on that, it should be easy to implement. Look at doit_cmd.py:DoitMain.run().

andersonbrands commented 1 year ago

What I do is something like this:

def task(func):
    func.create_doit_tasks = func
    return func

DOIT_CONFIG = {
    'default_tasks': ['_list'],
}

@task
def _list():
    return dict(actions=["doit list"])

Then using just doit will list all other tasks I have.

... Update: just read that you mentioned

I tried to create a task in dodo.py, which calls dodo list itself, but it won't work, because it needs to lock the DB.

So, I'm not sure my approach is equivalent to that tentative