擅长:python、mysql、java
<p>结构参数是通过非常基本的字符串解析来理解的,因此在发送它们时必须稍微小心一点。</p>
<p>下面是几种不同的方法向以下测试函数传递参数的示例:</p>
<pre><code>@task
def test(*args, **kwargs):
print("args:", args)
print("named args:", kwargs)
</code></pre>
<hr/>
<pre><code>$ fab "test:hello world"
('args:', ('hello world',))
('named args:', {})
$ fab "test:hello,world"
('args:', ('hello', 'world'))
('named args:', {})
$ fab "test:message=hello world"
('args:', ())
('named args:', {'message': 'hello world'})
$ fab "test:message=message \= hello\, world"
('args:', ())
('named args:', {'message': 'message = hello, world'})
</code></pre>
<p>我在这里使用双引号将shell从等式中去掉,但是单引号对于某些平台可能更好。还要注意fabric考虑分隔符的字符的转义。</p>
<p>文档中的更多详细信息:
<a href="http://docs.fabfile.org/en/1.14/usage/fab.html#per-task-arguments" rel="nofollow noreferrer">http://docs.fabfile.org/en/1.14/usage/fab.html#per-task-arguments</a></p>