Fix Python – Pass parameter to fabric task

Question

Asked By – Donovan

How can I pass a parameter to a fabric task when calling “fab” from the command line? For example:

def task(something=''):
    print "You said %s" % something
$ fab task "hello"
You said hello

Done.

Is it possible to do this without prompting with fabric.operations.prompt?

Now we will see solution for issue: Pass parameter to fabric task


Answer

Fabric 2 task arguments documentation:

http://docs.pyinvoke.org/en/latest/concepts/invoking-tasks.html#task-command-line-arguments


Fabric 1.X uses the following syntax for passing arguments to tasks:

 fab task:'hello world'
 fab task:something='hello'
 fab task:foo=99,bar=True
 fab task:foo,bar

You can read more about it in Fabric docs.

This question is answered By – Jakub Roztocil

This answer is collected from stackoverflow and reviewed by FixPython community admins, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0