Skip to content

Commit

Permalink
fix parsing of tanzu cli
Browse files Browse the repository at this point in the history
  • Loading branch information
ali5ter committed May 19, 2023
1 parent 3905696 commit 1ff7eda
Show file tree
Hide file tree
Showing 12 changed files with 1,295 additions and 897 deletions.
22 changes: 21 additions & 1 deletion cli_taxo.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@
HELP_OPT = '-h'
HELP_OPT_POSITIONS = Enum('HELP_OPT_POSITIONS', 'before after')
HELP_OPT_POSITION = HELP_OPT_POSITIONS.after.name
USAGE_TOKEN_RE = '^(Usage:)|^(Usage of)'
USAGE_RE = '^\s+?(\w+?)\s+'
OPTIONS_TOKEN_RE = '^Options:'
OPTIONS_RE = '^\s+?(-.+?)\s\s'
COMMANDS_TOKEN_RE = '^(Commands:)|^(Management Commands:)'
COMMANDS_RE = '^\s+(\w+?)\s+'
SHOW_OPTIONS = False
SHOW_COMMANDS = True
SHOW_USAGE = True
EXCLUDE_HELP_OPTS = False
OUTPUT_FORMATS = Enum('OUTPUT_FORMATS', 'tree csv table bash zsh')
OUTPUT_FORMAT = OUTPUT_FORMATS.tree.name
Expand Down Expand Up @@ -115,7 +118,10 @@ def parse_options_and_commands(command, depth=-1):
' '*depth+Fore.GREEN,
' '.join(map(str, command)),
Fore.RESET))

if USAGE_TOKEN_RE:
found_usage = False
else:
found_usage = True
if OPTIONS_TOKEN_RE:
found_options = False
else:
Expand All @@ -136,6 +142,7 @@ def parse_options_and_commands(command, depth=-1):
if _DEBUG:
eprint("\n{:s}[{:s}{:s}] Line >>{:s}<<{:s}".format(
' '*depth+Style.DIM,
'U✓' if found_usage else 'U ',
'C✓' if found_commands else 'C ',
'O✓' if found_options else 'O ',
line, Style.RESET_ALL))
Expand Down Expand Up @@ -172,6 +179,19 @@ def parse_options_and_commands(command, depth=-1):
_command.extend([HELP_OPT, match])
parse_options_and_commands(_command, depth)

# if _USAGE_TOKEN_RE.search(line) and not found_usage:
# found_usage = True
# if _USAGE_RE.search(line) and SHOW_USAGE and found_usage:
# for match in _USAGE_RE.search(line).groups():
# if _DEBUG:
# eprint('{:s} Usage match: >>{:s}<<'.format(
# ' '*depth, match))
# if match and not (_HELP_RE.search(match)
# and EXCLUDE_HELP_OPTS):
# content = format_item(depth, command, match)
# if content is not None:
# print(content)

depth -= 1

def format_item(depth, command, item):
Expand Down
103 changes: 24 additions & 79 deletions exp1/results/tanzu_taxo.txt
Original file line number Diff line number Diff line change
@@ -1,106 +1,51 @@
tanzu
└── builder
│ └── cli
│ │ └── add-plugin
│ │ └── compile
│ └── init
└── cluster
│ └── create
│ └── credentials
│ │ └── update
│ └── delete
│ └── get
│ └── kubeconfig
│ │ └── get
│ └── list
│ └── node-pool
│ │ └── delete
│ │ └── list
│ │ └── set
│ └── scale
│ └── upgrade
└── conformance
│ └── delete
│ └── gen
│ └── logs
│ └── results
│ └── retrieve
│ └── run
│ └── status
│ └── version
└── diagnostics
│ └── collect
│ └── completion
│ │ └── bash
│ │ └── fish
│ │ └── powershell
│ │ └── zsh
└── kubernetes-release
│ └── activate
│ └── deactivate
│ └── publish
└── ceip-participation
│ └── get
│ └── os
│ │ └── get
└── management-cluster
│ └── create
│ └── credentials
│ │ └── update
│ └── delete
│ └── get
│ └── kubeconfig
│ │ └── get
│ └── permissions
│ │ └── aws
│ │ │ └── set
│ └── register
│ └── upgrade
└── package
│ └── available
│ │ └── get
│ │ └── list
│ └── install
│ └── installed
│ │ └── create
│ │ └── delete
│ │ └── get
│ │ └── list
│ │ └── update
│ └── repository
│ └── set
└── completion
└── config
│ └── cert
│ │ └── add
│ │ └── delete
│ │ └── get
│ │ └── list
│ │ └── update
└── standalone-cluster
│ └── completion
│ │ └── bash
│ │ └── fish
│ │ └── powershell
│ │ └── zsh
│ └── create
│ └── delete
└── completion
└── config
│ └── eula
│ │ └── accept
│ │ └── show
│ └── get
│ └── init
│ └── server
│ │ └── delete
│ │ └── list
│ └── set
│ └── unset
└── context
│ └── create
│ └── delete
│ └── get
│ └── list
│ └── use
└── init
└── login
└── plugin
│ └── clean
│ └── delete
│ └── describe
│ └── group
│ │ └── get
│ │ └── search
│ └── install
│ └── list
│ └── repo
└── add
│ └── search
│ └── source
│ │ └── delete
│ │ └── init
│ │ └── list
│ │ └── update
│ └── sync
│ └── upgrade
└── update
└── version
└── kubernetes
└── mission-control
Loading

0 comments on commit 1ff7eda

Please sign in to comment.