Skip to content

Commit 7b6db96

Browse files
committed
Added labels for each command help text
1 parent 20dec6d commit 7b6db96

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

examples/scripts/save_help_text.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
import tempfile
1212
from typing import List
1313

14+
ASTERISKS = "********************************************************"
15+
1416

1517
def get_sub_commands(parser: argparse.ArgumentParser) -> List[str]:
1618
"""Returns a list of sub-commands for an ArgumentParser"""
@@ -43,7 +45,7 @@ def get_sub_commands(parser: argparse.ArgumentParser) -> List[str]:
4345
elif len(sys.argv) != 2:
4446
print("Usage: {} <output_file>".format(os.path.basename(sys.argv[0])))
4547
else:
46-
outfile = sys.argv[1]
48+
outfile = os.path.expanduser(sys.argv[1])
4749

4850
# Get a list of all commands and help topics and then filter out duplicates
4951
to_print = set(self.get_all_commands()) | set(self.get_help_topics())
@@ -55,11 +57,20 @@ def get_sub_commands(parser: argparse.ArgumentParser) -> List[str]:
5557
temp.write('!rm -f {}\n'.format(outfile))
5658

5759
for item in to_print:
60+
header = '{}\\nCOMMAND: {}\\n{}\\n'.format(ASTERISKS, item, ASTERISKS)
61+
temp.write('py print("{}") >> {}\n'.format(header, outfile))
5862
temp.write('help {} >> {}\n'.format(item, outfile))
5963

6064
# Add any sub-commands
6165
for subcmd in get_sub_commands(getattr(self.cmd_func(item), 'argparser', None)):
62-
temp.write('help {} {} >> {}\n'.format(item, subcmd, outfile))
66+
full_cmd = '{} {}'.format(item, subcmd)
67+
header = '{}\\nCOMMAND: {}\\n{}\\n'.format(ASTERISKS, full_cmd, ASTERISKS)
68+
69+
temp.write('py print("{}") >> {}\n'.format(header, outfile))
70+
temp.write('help {} >> {}\n'.format(full_cmd, outfile))
71+
72+
# Inform the user where output was written
73+
temp.write('py print("Output written to {}")\n'.format(outfile))
6374

6475
# Have the script delete itself as its last step
6576
temp.write('!rm -f {}\n'.format(temp.name))

0 commit comments

Comments
 (0)