diff --git a/.changelog/21.bugfix b/.changelog/21.bugfix new file mode 100644 index 00000000..f4bb88a3 --- /dev/null +++ b/.changelog/21.bugfix @@ -0,0 +1 @@ +Running `fil-profile` with no arguments now prints the help. \ No newline at end of file diff --git a/filprofiler/_script.py b/filprofiler/_script.py index 4b25c420..7c2e4901 100644 --- a/filprofiler/_script.py +++ b/filprofiler/_script.py @@ -100,19 +100,16 @@ def stage_1(): parser_run = subparsers.add_parser( "run", help="Run a Python script or package", prefix_chars=[""], add_help=False, ) -# parser_run.add_argument( -# "-m", -# dest="module", -# action="store", -# help="Profile a module, equivalent to running with 'python -m '", -# default="", -# ) parser_run.add_argument("rest", nargs=REMAINDER) del subparsers, parser_run def stage_2(): - """Main CLI interface. Presumes LD_PRELOAD etc. has been set by stage_1().""" + """Main CLI interface.22 Presumes LD_PRELOAD etc. has been set by stage_1().""" + if len(sys.argv) == 1: + PARSER.print_help() + sys.exit(0) + arguments = PARSER.parse_args() if arguments.license: print(LICENSE) diff --git a/tests/test_endtoend.py b/tests/test_endtoend.py index 4a76d537..e477174f 100644 --- a/tests/test_endtoend.py +++ b/tests/test_endtoend.py @@ -243,3 +243,14 @@ def test_external_behavior(): assert url.startswith("file://") assert url.endswith(".html") assert os.path.exists(url[len("file://") :]) + + +def test_no_args(): + """ + Running fil-profile with no arguments gives same result as --help. + """ + no_args = run(["fil-profile"], stdout=PIPE, stderr=PIPE) + with_help = run(["fil-profile", "--help"], stdout=PIPE, stderr=PIPE) + assert no_args.returncode == with_help.returncode + assert no_args.stdout == with_help.stdout + assert no_args.stderr == with_help.stderr