开发者

Fabfiles With Command Line Arguments

开发者 https://www.devze.com 2022-12-31 11:07 出处:网络
Is there a clean way to have your fabfile take command line arguments?I\'m writing an installation script for a tool that I want to be able to specify an optional target directory via the command line

Is there a clean way to have your fabfile take command line arguments? I'm writing an installation script for a tool that I want to be able to specify an optional target directory via the command line.

I wrote some code开发者_运维知识库 to test what would happen if I passed in some command line arguments:

# fabfile.py
import sys

def install():
    _get_options()

def _get_options():
    print repr(sys.argv[1:])

A couple of runs:

$ fab install
['install']

Done.
$ fab install --electric-boogaloo
Usage: fab [options] <command>[:arg1,arg2=val2,host=foo,hosts='h1;h2',...] ...

fab: error: no such option: --electric-boogaloo


I ended up using the per-task arguments. It seems like a better idea than doing unattached command line arguments.

0

精彩评论

暂无评论...
验证码 换一张
取 消