Skip to content

Commit 7a3011b

Browse files
authored
feat: allow hyphens in custom command names and aliases
1 parent 1558c0f commit 7a3011b

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

docs/README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -124,15 +124,15 @@ Example:
124124

125125
```python
126126
MANAGEMENT_COMMANDS_PATHS = {
127-
"mycommand": "mysite.commands.MyCommand",
127+
"my-command": "mysite.commands.MyCommand",
128128
}
129129
```
130130

131-
You can now run the custom command `mycommand` implemented in the `MyCommand` class
131+
You can now run the custom command `my-command` implemented in the `MyCommand` class
132132
from the `mysite.commands` module:
133133

134134
```console
135-
python manage.py mycommand
135+
python manage.py my-command
136136
```
137137

138138
> In Django, the class representing a command must be named `Command`. The plugin
@@ -141,8 +141,8 @@ python manage.py mycommand
141141
142142
**Important Notes:**
143143

144-
- All keys and values must be valid Python identifiers and absolute dotted paths,
145-
respectively.
144+
- All keys and values must be valid Python identifiers (with hyphens allowed) and
145+
absolute dotted paths, respectively.
146146
- Paths must point to command classes, not modules.
147147
- Commands must subclass `django.core.management.base.BaseCommand`.
148148
- This setting takes precedence over others when discovering commands.
@@ -214,26 +214,26 @@ Example:
214214

215215
```python
216216
MANAGEMENT_COMMANDS_ALIASES = {
217-
"fullcheck": [
217+
"full-check": [
218218
"check --fail-level ERROR --deploy",
219219
"makemigrations --check --dry-run --no-input",
220220
"migrate --no-input",
221221
],
222222
}
223223
```
224224

225-
You can now execute all the commands aliased by `fullcheck` with a single command:
225+
You can now execute all the commands aliased by `full-check` with a single command:
226226

227227
```console
228-
python manage.py fullcheck
228+
python manage.py full-check
229229
```
230230

231231
Aliases can refer to commands defined in the `MANAGEMENT_COMMANDS_PATHS` setting
232232
or other aliases.
233233

234234
**Important Notes:**
235235

236-
- Keys must be valid Python identifiers.
236+
- Keys must be valid Python identifiers (with hyphens allowed).
237237
- Values should be command expressions with parsable arguments and options.
238238
- Circular references within aliases are not allowed, as they lead to infinite recursion.
239239

src/management_commands/conf.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99

1010
def _is_identifier(s: str) -> bool:
11-
return s.isidentifier() and not iskeyword(s)
11+
return s.replace("-", "_").isidentifier() and not iskeyword(s)
1212

1313

1414
def _is_dotted_path(s: str, /, *, min_parts: int = 0) -> bool:
@@ -53,7 +53,7 @@ def configure_paths(self, setting_value: dict[str, str]) -> dict[str, str]:
5353
if not _is_identifier(key):
5454
msg = (
5555
f"invalid key {key!r} in PATHS; "
56-
f"keys must be valid Python identifiers"
56+
f"keys must be valid Python identifiers (with hyphens allowed)"
5757
)
5858

5959
raise self.improperly_configured(msg, "paths.key")
@@ -103,7 +103,7 @@ def configure_aliases(
103103
if not _is_identifier(key):
104104
msg = (
105105
f"invalid key {key!r} in ALIASES; "
106-
f"keys must be valid Python identifiers"
106+
f"keys must be valid Python identifiers (with hyphens allowed)"
107107
)
108108

109109
raise self.improperly_configured(msg, "aliases.key")

0 commit comments

Comments
 (0)