Skip to content

Commit ac0f82b

Browse files
authored
Merge pull request #22 from pythonspeed/21-no-args
Fix running with no command-line arguments.
2 parents f8901da + 59b60a4 commit ac0f82b

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

.changelog/21.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Running `fil-profile` with no arguments now prints the help.

filprofiler/_script.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,19 +100,16 @@ def stage_1():
100100
parser_run = subparsers.add_parser(
101101
"run", help="Run a Python script or package", prefix_chars=[""], add_help=False,
102102
)
103-
# parser_run.add_argument(
104-
# "-m",
105-
# dest="module",
106-
# action="store",
107-
# help="Profile a module, equivalent to running with 'python -m <module>'",
108-
# default="",
109-
# )
110103
parser_run.add_argument("rest", nargs=REMAINDER)
111104
del subparsers, parser_run
112105

113106

114107
def stage_2():
115-
"""Main CLI interface. Presumes LD_PRELOAD etc. has been set by stage_1()."""
108+
"""Main CLI interface.22 Presumes LD_PRELOAD etc. has been set by stage_1()."""
109+
if len(sys.argv) == 1:
110+
PARSER.print_help()
111+
sys.exit(0)
112+
116113
arguments = PARSER.parse_args()
117114
if arguments.license:
118115
print(LICENSE)

tests/test_endtoend.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,3 +243,14 @@ def test_external_behavior():
243243
assert url.startswith("file://")
244244
assert url.endswith(".html")
245245
assert os.path.exists(url[len("file://") :])
246+
247+
248+
def test_no_args():
249+
"""
250+
Running fil-profile with no arguments gives same result as --help.
251+
"""
252+
no_args = run(["fil-profile"], stdout=PIPE, stderr=PIPE)
253+
with_help = run(["fil-profile", "--help"], stdout=PIPE, stderr=PIPE)
254+
assert no_args.returncode == with_help.returncode
255+
assert no_args.stdout == with_help.stdout
256+
assert no_args.stderr == with_help.stderr

0 commit comments

Comments
 (0)