azhelp.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:pyladies-march2017 作者: dmahugh 项目源码 文件源码
def getcommands(helpcmd):
    """Recursively crawl all subgroups, starting from specified help command.
    Passed command assumed to end with -h. For example, 'az vm -h'
    """
    indentation = 4 * (len(helpcmd.split(' ')) - 3)
    print(indentation*' ' + helpcmd)

    stdoutdata = subprocess.getoutput(helpcmd) # capture help command output
    subgroups = False # flag to track whether inside the subgroup section
    for line in stdoutdata.split('\n'):

        if line.strip() == 'Subgroups:':
            subgroups = True # found start of subgroup section
            continue # skip the 'Subgroups:' line
        if not subgroups:
            continue # skip all lines before subgroup section
        if subgroups and (not line.strip() or line.lstrip() == line):
            break # blank or non-indented line is end of subgroup section

        subhelp = subcommand(helpcmd, line) # create help command for subgroup
        getcommands(subhelp) # enumerate help commands for this subgroup
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号