Skip to content

Commit f699285

Browse files
authored
Merge pull request #139 from techtonik/humanhelp
Print help for humans, fixes #124
2 parents 6cde86e + 7121af1 commit f699285

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

gitless/cli/gl.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,28 @@
5050
pass
5151

5252

53+
def print_help(parser):
54+
"""print help for humans"""
55+
print(parser.description)
56+
print('\ncommands:\n')
57+
58+
# https://stackoverflow.com/questions/20094215/argparse-subparser-monolithic-help-output
59+
# retrieve subparsers from parser
60+
subparsers_actions = [
61+
action for action in parser._actions
62+
if isinstance(action, argparse._SubParsersAction)]
63+
# there will probably only be one subparser_action,
64+
# but better save than sorry
65+
for subparsers_action in subparsers_actions:
66+
# get all subparsers and print help
67+
for choice in subparsers_action._choices_actions:
68+
print(' {:<19} {}'.format(choice.dest, choice.help))
69+
5370
def main():
5471
parser = argparse.ArgumentParser(
5572
description=(
56-
'Gitless: a version control system built on top of Git. More info, '
57-
'downloads and documentation available at {0}'.format(URL)),
73+
'Gitless: a version control system built on top of Git.\nMore info, '
74+
'downloads and documentation at {0}'.format(URL)),
5875
formatter_class=argparse.RawDescriptionHelpFormatter)
5976
parser.add_argument(
6077
'--version', action='version', version=(
@@ -71,7 +88,7 @@ def main():
7188
sub_cmd.parser(subparsers, repo)
7289

7390
if len(sys.argv) == 1:
74-
parser.print_help()
91+
print_help(parser)
7592
return SUCCESS
7693

7794
args = parser.parse_args()

0 commit comments

Comments
 (0)