Task title created by `title_with_actions` does not replace parameter and options values.
Consider the following dodo.py file:
from doit.tools import title_with_actions
DOIT_CONFIG = {'default_tasks': ['mytask']}
def task_mytask():
return {
# 'name': 'mysubtask',
'params': [{
'name': 'myparam',
'short': 'p',
'long': 'myparam',
'default': 'param_default',
}],
'actions': ["echo myparam is %(myparam)s"],
'title': title_with_actions,
'verbosity': 2,
}
Executing it yields:
>>> doit
. mytask => Cmd: echo myparam is %(myparam)s
myparam is param_default
You can notice that the title created for the action is not correct: one would expect to see
Cmd: echo myparam is param_default, in other words one would expect that this title, since it is created after task instantiation, actually represents what will be executed.
I see two ways to fix this:
- fixing only the
title_with_actionsmethod. This would force us to write an ugly if/elif statement in it to support all kind ofBaseActionsubtypes. - fixing the
__str__in allBaseActionsubtypes directly. For example forCmdAction:
def __str__(self):
# try to replace all options in the various commands
try:
_action = self.expand_action()
except Exception:
_action = self._action
return "Cmd: %s" % _action
Your example can be written like this:
DOIT_CONFIG = {'default_tasks': ['mytask']}
def task_mytask():
return {
# 'name': 'mysubtask',
'params': [{
'name': 'myparam',
'short': 'p',
'long': 'myparam',
'default': 'param_default',
}],
'actions': ["echo myparam is %(myparam)s"],
'title': lambda t: str(t.actions[0]) % t.options,
'verbosity': 2,
}
It is trivial to write your own, and does not require changes in doit core.
Said that, I would not oppose to a change in title_with_actions.
Thanks for the tip ! Even if users can customize many things, I guess that they prefer not to do so, so as to keep their code readable. So I'll try to propose a PR.