Since CmdAction
can take a str
or List[str]
and also callable
that returns the action - can the callable also return a List[str]
? This would be helpful if you wanted to call something without a shell and still wanted to get or construct arguments from other tasks' output.
import logging
import shlex
from typing import List
import doit
from doit.action import CmdAction
DOIT_CONFIG = {
'verbosity': 2,
'default_tasks': ['check_results']
}
def task_check_results():
def check_results(use_foo_bar, use_foo_bar_shlex):
failed = False
logging.warning('use_foo_bar = %s', use_foo_bar)
if use_foo_bar != 'Used "foo bar"':
failed = True
logging.warning('use_foo_bar_shlex = %s', use_foo_bar_shlex)
if use_foo_bar_shlex != 'Used "foo bar"':
failed = True
return not failed
return {
'actions': [check_results],
'getargs': {
'use_foo_bar': ('use_foo_bar', 'stdout'),
'use_foo_bar_shlex': ('use_foo_bar_shlex', 'stdout'),
}
}
def task_echo_foo_bar():
return {
'actions': [CmdAction(['echo', '-n', 'foo bar'], shell=False, save_out='stdout')],
}
def task_use_foo_bar():
def use_foo_bar(foo_bar: str) -> List[str]:
return ['echo', '-n', f'Used "{foo_bar}"']
return {
'actions': [CmdAction(use_foo_bar, save_out='stdout')],
'getargs': {
'foo_bar': ('echo_foo_bar', 'stdout'),
},
'uptodate': [False],
}
def task_use_foo_bar_shlex():
def use_foo_bar(foo_bar: str) -> str:
return shlex.join(['echo', '-n', f'Used "{foo_bar}"'])
return {
'actions': [CmdAction(use_foo_bar, executable='bash', save_out='stdout')],
'getargs': {
'foo_bar': ('echo_foo_bar', 'stdout'),
},
'uptodate': [False],
}
if __name__ == '__main__':
doit.run(globals())
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too