Skip to content

Commit dc67537

Browse files
committed
Extract writing an index to a separate file
1 parent d07fab6 commit dc67537

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

awsshell/makeindex.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,21 +53,27 @@ def index_command(index_dict, help_command):
5353
index_command(child, sub_help_command)
5454

5555

56-
def main():
57-
parser = argparse.ArgumentParser()
58-
parser.add_argument('-o', '--output',
59-
help='The filename of the index file.')
60-
args = parser.parse_args()
61-
if args.output is None:
62-
args.output = determine_index_filename()
56+
def write_index(output_filename=None):
57+
if output_filename is None:
58+
output_filename = determine_index_filename()
6359
driver = awscli.clidriver.create_clidriver()
6460
help_command = driver.create_help_command()
6561
index = {'aws': new_index()}
6662
current = index['aws']
6763
index_command(current, help_command)
6864

6965
result = pprint.pformat(index)
70-
if not os.path.isdir(os.path.dirname(args.output)):
71-
os.makedirs(os.path.dirname(args.output))
72-
with open(args.output, 'w') as f:
66+
if not os.path.isdir(os.path.dirname(output_filename)):
67+
os.makedirs(os.path.dirname(output_filename))
68+
with open(output_filename, 'w') as f:
7369
f.write(result)
70+
71+
72+
def main():
73+
parser = argparse.ArgumentParser()
74+
parser.add_argument('-o', '--output',
75+
help='The filename of the index file.')
76+
args = parser.parse_args()
77+
if args.output is None:
78+
args.output = determine_index_filename()
79+
write_index(args.output)

0 commit comments

Comments
 (0)