Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/dotenv/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def unset(ctx: click.Context, key: Any) -> None:
sys.exit(1)


@cli.command(context_settings={"ignore_unknown_options": True})
@cli.command(context_settings={"ignore_unknown_options": True}, add_help_option=False)
@click.pass_context
@click.option(
"--override/--no-override",
Expand All @@ -180,6 +180,9 @@ def run(ctx: click.Context, override: bool, commandline: List[str]) -> None:
if not commandline:
click.echo("No command given.")
sys.exit(1)
if len(commandline) == 1 and commandline[0] in ["-h", "--help"]:
click.echo(ctx.get_help())
sys.exit(0)
run_command(commandline, dotenv_as_dict)


Expand Down
19 changes: 19 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import subprocess
from pathlib import Path
from typing import Optional

Expand Down Expand Up @@ -249,3 +250,21 @@ def test_run_with_version(cli):

assert result.exit_code == 0
assert result.output.strip().endswith(__version__)


def test_run_subcommand_with_help_uses_subcommand_help(cli, dotenv_path):
dotenv_path.write_text("a=b")
output = sh.dotenv("--file", dotenv_path, "run", "printenv", "--help")

assert "dotenv run" not in output
expected_help_output = subprocess.check_output(["printenv", "--help"]).decode(
"utf-8"
)
assert output == expected_help_output


def test_run_with_just_help_show_help(cli, dotenv_path):
dotenv_path.write_text("a=b")
output = sh.dotenv("--file", dotenv_path, "run", "--help")

assert "dotenv run" in output