Skip to content

Commit a1ace48

Browse files
gwerbingvanrossum
authored andcommitted
Make stubgen return status 0 on --help (#4160)
1 parent 23b71df commit a1ace48

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

mypy/stubgen.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -908,7 +908,7 @@ def parse_options(args: List[str]) -> Options:
908908
elif args[0] == '--include-private':
909909
include_private = True
910910
elif args[0] in ('-h', '--help'):
911-
usage()
911+
usage(exit_nonzero=False)
912912
else:
913913
raise SystemExit('Unrecognized option %s' % args[0])
914914
args = args[1:]
@@ -943,7 +943,7 @@ def default_python2_interpreter() -> str:
943943
raise SystemExit("Can't find a Python 2 interpreter -- please use the -p option")
944944

945945

946-
def usage() -> None:
946+
def usage(exit_nonzero: bool=True) -> None:
947947
usage = textwrap.dedent("""\
948948
usage: stubgen [--py2] [--no-import] [--doc-dir PATH]
949949
[--search-path PATH] [-p PATH] [-o PATH]
@@ -976,7 +976,13 @@ def usage() -> None:
976976
-h, --help print this help message and exit
977977
""".rstrip())
978978

979-
raise SystemExit(usage)
979+
if exit_nonzero:
980+
# The user made a mistake, so we should return with an error code
981+
raise SystemExit(usage)
982+
else:
983+
# The user asked for help specifically, so we should exit with success
984+
print(usage, file=sys.stderr)
985+
sys.exit()
980986

981987

982988
if __name__ == '__main__':

0 commit comments

Comments
 (0)