Skip to content

Commit 2657d43

Browse files
committed
Flag which options are required
1 parent 611bebc commit 2657d43

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

awsshell/__init__.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,14 @@ def get_completions(self, document, complete_event):
4545
if text_before_cursor.strip():
4646
word_before_cursor = text_before_cursor.split()[-1]
4747
completions = self._completer.autocomplete(text_before_cursor)
48+
required_args = set(self._completer.required_args)
4849
for completion in completions:
50+
if completion.startswith('--') and completion in required_args:
51+
display_text = '%s (required)' % completion
52+
else:
53+
display_text = completion
4954
yield Completion(completion, -len(word_before_cursor),
50-
display_meta='')
55+
display=display_text)
5156

5257

5358
def main():
@@ -61,6 +66,7 @@ def main():
6166
while True:
6267
try:
6368
text = get_input('aws> ', completer=completer,
69+
display_completions_in_columns=True,
6470
history=history)
6571
except (KeyboardInterrupt, EOFError):
6672
break

awsshell/autocomplete.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ def __init__(self, index_data):
2828
self._last_position = 0
2929
self._current_line = ''
3030

31+
@property
32+
def required_args(self):
33+
# Returns the required arguments for the current level.
34+
return self._current['required_arguments']
35+
3136
def reset(self):
3237
# Resets all the state. Called after a user runs
3338
# a command.

awsshell/makeindex.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,21 @@
1313
from awsshell import determine_index_filename
1414

1515

16-
# arguments/commands are used for completions
17-
# children is used for further indexing of subcommands.
18-
INDEX = {'aws': {'arguments': [], 'commands': [], 'children': {}}}
16+
def new_index():
17+
return {'arguments': [], 'required_arguments': [],
18+
'commands': [], 'children': {}}
1919

2020

2121
def index_command(index_dict, help_command):
22-
for arg in help_command.arg_table:
22+
arg_table = help_command.arg_table
23+
for arg in arg_table:
24+
if arg_table[arg].required:
25+
index_dict['required_arguments'].append('--%s' % arg)
2326
index_dict['arguments'].append('--%s' % arg)
2427
for cmd in help_command.command_table:
2528
index_dict['commands'].append(cmd)
2629
# Each sub command will trigger a recurse.
27-
child = {'arguments': [], 'commands': [], 'children': {}}
30+
child = new_index()
2831
index_dict['children'][cmd] = child
2932
sub_command = help_command.command_table[cmd]
3033
sub_help_command = sub_command.create_help_command()
@@ -40,10 +43,11 @@ def main():
4043
args.output = determine_index_filename()
4144
driver = awscli.clidriver.create_clidriver()
4245
help_command = driver.create_help_command()
43-
current = INDEX['aws']
46+
index = {'aws': new_index()}
47+
current = index['aws']
4448
index_command(current, help_command)
4549

46-
result = pprint.pformat(INDEX)
50+
result = pprint.pformat(index)
4751
if not os.path.isdir(os.path.dirname(args.output)):
4852
os.makedirs(os.path.dirname(args.output))
4953
with open(args.output, 'w') as f:

0 commit comments

Comments
 (0)