doit icon indicating copy to clipboard operation
doit copied to clipboard

Allow `list` to be used in `default_tasks`

Open mathbunnyru opened this issue 2 years ago • 2 comments

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

  • In the makefile, by default first target that does not begin with a . is called (https://stackoverflow.com/questions/2057689/how-does-make-app-know-default-target-to-build-if-no-target-is-specified). I can for example have a nice help command.
  • Always type "doit list", which is fine, but I would like the default to be nice
  • 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.
Fund with Polar

mathbunnyru avatar Mar 20 '22 11:03 mathbunnyru

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 or doit help for 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().

schettino72 avatar Mar 20 '22 11:03 schettino72

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

andersonbrands avatar Jan 09 '23 14:01 andersonbrands