Skip to content

Commit

Permalink
fix: jans-cli help message format and prompt values (ref: #1352) (#1478)
Browse files Browse the repository at this point in the history
* fix: jans-cli help message format and prompt values (ref: #1352)

* fix: jans-cli hide menu items if plugin unavailable
  • Loading branch information
devrimyatar authored Jun 6, 2022
1 parent 808d0c4 commit 37a9181
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions jans-cli/cli/config_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,8 @@ def get_methods_of_tag(tag):
for method_name in path:
method = path[method_name]
if 'tags' in method and tag in method['tags'] and 'operationId' in method:
if method.get('x-cli-plugin') and method['x-cli-plugin'] not in plugins:
continue
method['__method_name__'] = method_name
method['__path_name__'] = path_name
methods.append(method)
Expand All @@ -484,10 +486,10 @@ def get_methods_of_tag(tag):


for grp in menu_groups:
methods = get_methods_of_tag(grp.tag)
m = Menu(name=grp.mname)
m.display_name = m.name + ' ˅'
menu.add_child(m)
methods = get_methods_of_tag(grp.tag)

for method in methods:
for tag in method['tags']:
Expand All @@ -503,10 +505,13 @@ def get_methods_of_tag(tag):
if grp.submenu:
m.display_name = m.name + ' ˅'
for sub in grp.submenu:
methods = get_methods_of_tag(sub.tag)
if not methods:
continue
smenu = Menu(name=sub.mname)
smenu.display_name = smenu.name + ' ˅'
m.add_child(smenu)
methods = get_methods_of_tag(sub.tag)

for method in methods:
for tag in method['tags']:

Expand Down Expand Up @@ -749,7 +754,12 @@ def get_input(self, values=[], text='Selection', default=None, itype=None,
example=None, spacing=0
):
if 'b' in values and 'q' in values and 'x' in values:
print(self.colored_text("b: back, q: quit x: logout and quit", grey_color))
greyed_help_list = [ ('b', 'back'), ('q', 'quit'), ('x', 'logout and quit') ]
for k,v in (('w', 'write result'), ('y', 'yes'), ('n', 'no')):
if k in values:
greyed_help_list.insert(1, (k, v))
grey_help_text = ', '.join(['{}: {}'.format(k,v) for k,v in greyed_help_list])
print(self.colored_text(grey_help_text, grey_color))
print()
type_text = ''
if itype:
Expand Down Expand Up @@ -1814,7 +1824,7 @@ def display_menu(self, menu):

c = 0
for i, item in enumerate(menu):
if item.info.get('x-cli-ignore'):
if item.info.get('x-cli-ignore') or not item.children:
continue
print(c + 1, item)
selection_values.append(str(c + 1))
Expand Down

0 comments on commit 37a9181

Please sign in to comment.