Repository: pypa/hatch

Issue:
hatch run --help does not work as expected
This is a minor issue.

Unlike the other `hatch` CLI commands, `hatch run --help` does not print the full help output. Instead, the result is:

```
Missing argument `MATRIX:ARGS...`
```

A nice docstring is already defined in `hatch.cli.run.run`:

https://github.com/pypa/hatch/blob/9022c6df9602a0c2bb3b748be95a3d3114caf39d/src/hatch/cli/run/__init__.py#L12-L52

At a glance, it seems like this could be fixed by adding special handling of the argument `--help` in that function:

https://github.com/pypa/hatch/blob/9022c6df9602a0c2bb3b748be95a3d3114caf39d/src/hatch/cli/run/__init__.py#L55-L71

Discussion:

Patch:
diff --git a/docs/history.md b/docs/history.md
index af473ac4..8627607c 100644
--- a/docs/history.md
+++ b/docs/history.md
@@ -10,6 +10,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
 
 ### Unreleased
 
+***Fixed:***
+
+- Support `-h`/`--help` flag for the `run` command
+
 ### [1.3.0](https://github.com/pypa/hatch/releases/tag/hatch-v1.3.0) - 2022-07-10 ### {: #hatch-v1.3.0 }
 
 ***Changed:***
diff --git a/src/hatch/cli/run/__init__.py b/src/hatch/cli/run/__init__.py
index b442c280..0559fc7d 100644
--- a/src/hatch/cli/run/__init__.py
+++ b/src/hatch/cli/run/__init__.py
@@ -50,6 +50,10 @@ def run(ctx, app, args):
     would execute `pytest` in the environments `test.py310-42` and `test.py310-3.14`.
     Note that `py` may be used as an alias for `python`.
     """
+    if args[0] in ('-h', '--help'):
+        app.display_info(ctx.get_help())
+        return
+
     from hatch.cli.env.run import run as run_command
 
     command_start = 0


Test patch:
diff --git a/tests/cli/run/test_run.py b/tests/cli/run/test_run.py
index e9536642..12cbbc5a 100644
--- a/tests/cli/run/test_run.py
+++ b/tests/cli/run/test_run.py
@@ -7,6 +7,16 @@ from hatch.project.core import Project
 from hatch.utils.structures import EnvVars
 
 
+def test_help(hatch):
+    short = hatch('run', '-h')
+    assert short.exit_code == 0, short.output
+
+    long = hatch('run', '--help')
+    assert long.exit_code == 0, long.output
+
+    assert short.output == long.output
+
+
 def test_automatic_creation(hatch, helpers, temp_dir, config_file):
     config_file.model.template.plugins['default']['tests'] = False
     config_file.save()