[Python] How to pass arguments to python fabric task

Discussão em 'Python' iniciado por Stack, Agosto 27, 2025.

  1. Stack

    Stack Membro Participativo

    For fabric 2+ (specifically latest=3.2.2), how am I supposed to pass an argument to my task from the command line?

    (venv) ubuntu@ip-x-x-x-x:~/workspace/repo/tasks$ fab set-debug -v true
    No idea what 'true' is!
    (venv) ubuntu@ip-x-x-x-x:~/workspace/repo/tasks$ fab set-debug --help
    Usage: fab [--core-opts] set-debug [--options] [other tasks here ...]

    Docstring:
    none

    Options:
    -v, --value


    This happens for all defined tasks, args, kwargs and when using other fab core opts (e.g. -H, -f), but as an example:

    in fabfile/tasks.py

    @task
    def set_debug(c, value=False):
    SCRIPTS_DIR = os.path.join(APP_ROOT, "bin")
    script = os.path.join(SCRIPTS_DIR, "set_debug.sh")
    c.sudo(f"{script} {str(value).capitalize()}")


    in fabfile/__init__.py

    from invoke import Collection

    from . import tasks

    ns = Collection(tasks)


    I have read through all of invoke and fabric documentation trying to find the correct way to do this. The task runs fine when using the default / no arguments.

    Relevant discussions that didn't work for me:


    Continue reading...

Compartilhe esta Página