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
评论列表
文章目录