Skip to main content
 首页 » 编程设计

python之如何在 Fabric 中创建自定义帮助菜单

2024年10月24日12youxin

当我运行 fab --list 时,我得到的输出为

error                        Call ``func`` with given error ``message``. 
get_all_tags 
get_head_position 
get_latest_patch 
get_latest_tag 
get_pending_patches 
glob                         Return a list of paths matching a pathname pattern. 
handle_prompt_abort 
help 
indent                       Return ``text`` indented by the given number of spaces. 

这包含几个用户定义的函数,如 get_all_tags get_head_position 等,但没有任何描述。
我希望也包括这些函数的描述,以便我的列表看起来像这样

error                        Call ``func`` with given error ``message``. 
get_all_tags                 Returns a list of all available tags 
get_head_position            Returns the current Head position 
get_latest_patch             Returns most recently created patch file name 
get_latest_tag               Returns the most recent tags among all the tags 
get_pending_patches          Returns list of all patches which are yet to be applied 
glob                         Return a list of paths matching a pathname pattern. 
handle_prompt_abort 
help 
indent                       Return ``text`` indented by the given number of spaces. 

我该怎么做?

请您参考如下方法:

将文档字符串添加到函数中。

@task 
def get_all_tags(): 
    "This is a docstring ..." 

文档字符串用于显示帮助信息。

根据 fab -l option documentation :

Imports a fabfile as normal, but then prints a list of all discovered tasks and exits. Will also print the first line of each task’s docstring, if it has one, next to it (truncating if necessary.)