Skip to content

Commit

Permalink
Lazy generation of usage help
Browse files Browse the repository at this point in the history
Instead having a string with all the possible actions for gordon, this
string is going to be generated with a lambda after the parser has all
the actions added to it.

Removing the usage kwarg to ArgumentParser we could achieve a similar
output:

  usage: gordon [-h] {startproject,startapp,build,apply,run,delete} ...

But to keep consistency with the previous output the lambda was added.
  • Loading branch information
agonzalezro committed Sep 13, 2016
1 parent b771be1 commit 090896e
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion gordon/bin.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ def main(argv=None, stdin=None):
stdin = stdin or sys.stdin
argv = (argv or sys.argv)[1:]

parser = argparse.ArgumentParser(usage=("%(prog)s [build | apply | startproject | startapp]"))
parser = argparse.ArgumentParser()
parser.format_usage = lambda: (
"usage: gordon [%s]\n" % ' | '.join(parser._actions[1].choices.keys())
)
subparsers = parser.add_subparsers()

def add_default_arguments(p):
Expand Down

0 comments on commit 090896e

Please sign in to comment.