Skip to content

Commit f717ccf

Browse files
committed
fix(cli/commands): add description for subcommands
1 parent 3e57007 commit f717ccf

11 files changed

+172
-4
lines changed

commitizen/cli.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,13 @@ def __call__(
114114
"commands": [
115115
{
116116
"name": ["init"],
117+
"description": "init commitizen configuration",
117118
"help": "init commitizen configuration",
118119
"func": commands.Init,
119120
},
120121
{
121122
"name": ["commit", "c"],
123+
"description": "create new commit",
122124
"help": "create new commit",
123125
"func": commands.Commit,
124126
"arguments": [
@@ -164,22 +166,31 @@ def __call__(
164166
},
165167
{
166168
"name": "ls",
169+
"description": "show available commitizens",
167170
"help": "show available commitizens",
168171
"func": commands.ListCz,
169172
},
170173
{
171174
"name": "example",
175+
"description": "show commit example",
172176
"help": "show commit example",
173177
"func": commands.Example,
174178
},
175179
{
176180
"name": "info",
181+
"description": "show information about the cz",
177182
"help": "show information about the cz",
178183
"func": commands.Info,
179184
},
180-
{"name": "schema", "help": "show commit schema", "func": commands.Schema},
185+
{
186+
"name": "schema",
187+
"description": "show commit schema",
188+
"help": "show commit schema",
189+
"func": commands.Schema,
190+
},
181191
{
182192
"name": "bump",
193+
"description": "bump semantic version based on the git log",
183194
"help": "bump semantic version based on the git log",
184195
"func": commands.Bump,
185196
"arguments": [
@@ -346,6 +357,9 @@ def __call__(
346357
},
347358
{
348359
"name": ["changelog", "ch"],
360+
"description": (
361+
"generate changelog (note that it will overwrite existing file)"
362+
),
349363
"help": (
350364
"generate changelog (note that it will overwrite existing file)"
351365
),
@@ -416,6 +430,7 @@ def __call__(
416430
},
417431
{
418432
"name": ["check"],
433+
"description": "validates that a commit message matches the commitizen schema",
419434
"help": "validates that a commit message matches the commitizen schema",
420435
"func": commands.Check,
421436
"arguments": [
@@ -455,6 +470,10 @@ def __call__(
455470
},
456471
{
457472
"name": ["version"],
473+
"description": (
474+
"get the version of the installed commitizen or the current project"
475+
" (default: installed commitizen)"
476+
),
458477
"help": (
459478
"get the version of the installed commitizen or the current project"
460479
" (default: installed commitizen)"

tests/commands/test_bump_command.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1449,3 +1449,15 @@ def test_bump_changelog_contains_increment_only(mocker, tmp_commitizen_project,
14491449

14501450
assert "3.0.0" in out
14511451
assert "2.0.0" not in out
1452+
1453+
1454+
def test_bump_command_shows_description_when_use_help_option(
1455+
mocker: MockFixture, capsys
1456+
):
1457+
testargs = ["cz", "bump", "--help"]
1458+
mocker.patch.object(sys, "argv", testargs)
1459+
with pytest.raises(SystemExit):
1460+
cli.main()
1461+
1462+
out, _ = capsys.readouterr()
1463+
assert "bump semantic version based on the git log" in str(out).replace("\n", " ")

tests/commands/test_changelog_command.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1637,3 +1637,17 @@ def test_export_changelog_template_from_plugin(
16371637

16381638
assert target.exists()
16391639
assert target.read_text() == tpl
1640+
1641+
1642+
def test_changelog_command_shows_description_when_use_help_option(
1643+
mocker: MockFixture, capsys
1644+
):
1645+
testargs = ["cz", "changelog", "--help"]
1646+
mocker.patch.object(sys, "argv", testargs)
1647+
with pytest.raises(SystemExit):
1648+
cli.main()
1649+
1650+
out, _ = capsys.readouterr()
1651+
assert ("generate changelog (note that it will overwrite existing file)") in str(
1652+
out
1653+
).replace("\n", " ")

tests/commands/test_check_command.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,3 +414,17 @@ def test_check_conventional_commit_succeed_with_git_diff(mocker, capsys):
414414
cli.main()
415415
out, _ = capsys.readouterr()
416416
assert "Commit validation: successful!" in out
417+
418+
419+
def test_check_command_shows_description_when_use_help_option(
420+
mocker: MockFixture, capsys
421+
):
422+
testargs = ["cz", "check", "--help"]
423+
mocker.patch.object(sys, "argv", testargs)
424+
with pytest.raises(SystemExit):
425+
cli.main()
426+
427+
out, _ = capsys.readouterr()
428+
assert "validates that a commit message matches the commitizen schema" in str(
429+
out
430+
).replace("\n", " ")

tests/commands/test_commit_command.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import os
2+
import sys
23

34
import pytest
45
from pytest_mock import MockFixture
56
from unittest.mock import ANY
67

7-
from commitizen import cmd, commands
8+
from commitizen import cli, cmd, commands
89
from commitizen.cz.exceptions import CzException
910
from commitizen.cz.utils import get_backup_file_path
1011
from commitizen.exceptions import (
@@ -406,3 +407,15 @@ def test_commit_command_with_message_length_limit(config, mocker: MockFixture):
406407

407408
with pytest.raises(CommitMessageLengthExceededError):
408409
commands.Commit(config, {"message_length_limit": message_length - 1})()
410+
411+
412+
def test_commit_command_shows_description_when_use_help_option(
413+
mocker: MockFixture, capsys
414+
):
415+
testargs = ["cz", "commit", "--help"]
416+
mocker.patch.object(sys, "argv", testargs)
417+
with pytest.raises(SystemExit):
418+
cli.main()
419+
420+
out, _ = capsys.readouterr()
421+
assert "create new commit" in str(out).replace("\n", " ")
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import pytest
2+
import sys
3+
from commitizen import cli
4+
5+
from pytest_mock import MockerFixture
6+
7+
8+
def test_example_command_shows_description_when_use_help_option(
9+
mocker: MockerFixture, capsys
10+
):
11+
testargs = ["cz", "example", "--help"]
12+
mocker.patch.object(sys, "argv", testargs)
13+
with pytest.raises(SystemExit):
14+
cli.main()
15+
16+
out, _ = capsys.readouterr()
17+
assert "show commit example" in str(out).replace("\n", " ")

tests/commands/test_info_command.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import pytest
2+
import sys
3+
from commitizen import cli
4+
5+
from pytest_mock import MockerFixture
6+
7+
8+
def test_info_command_shows_description_when_use_help_option(
9+
mocker: MockerFixture, capsys
10+
):
11+
testargs = ["cz", "info", "--help"]
12+
mocker.patch.object(sys, "argv", testargs)
13+
with pytest.raises(SystemExit):
14+
cli.main()
15+
16+
out, _ = capsys.readouterr()
17+
assert "show information about the cz" in str(out).replace("\n", " ")

tests/commands/test_init_command.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22

33
import json
44
import os
5+
import sys
56
from typing import Any
67

78
import pytest
89
import yaml
910
from pytest_mock import MockFixture
1011

11-
from commitizen import commands
12+
from commitizen import cli, commands
1213
from commitizen.__version__ import __version__
1314
from commitizen.exceptions import InitFailedError, NoAnswersError
1415

@@ -251,3 +252,15 @@ def test_pre_commit_exec_failed(
251252
with tmpdir.as_cwd():
252253
with pytest.raises(InitFailedError):
253254
commands.Init(config)()
255+
256+
257+
def test_init_command_shows_description_when_use_help_option(
258+
mocker: MockFixture, capsys
259+
):
260+
testargs = ["cz", "init", "--help"]
261+
mocker.patch.object(sys, "argv", testargs)
262+
with pytest.raises(SystemExit):
263+
cli.main()
264+
265+
out, _ = capsys.readouterr()
266+
assert "init commitizen configuration" in str(out).replace("\n", " ")

tests/commands/test_ls_command.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import pytest
2+
import sys
3+
from commitizen import cli
4+
5+
from pytest_mock import MockerFixture
6+
7+
8+
def test_ls_command_shows_description_when_use_help_option(
9+
mocker: MockerFixture, capsys
10+
):
11+
testargs = ["cz", "ls", "--help"]
12+
mocker.patch.object(sys, "argv", testargs)
13+
with pytest.raises(SystemExit):
14+
cli.main()
15+
16+
out, _ = capsys.readouterr()
17+
assert "show available commitizens" in str(out).replace("\n", " ")

tests/commands/test_schema_command.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import pytest
2+
import sys
3+
from commitizen import cli
4+
5+
from pytest_mock import MockerFixture
6+
7+
8+
def test_schema_command_shows_description_when_use_help_option(
9+
mocker: MockerFixture, capsys
10+
):
11+
testargs = ["cz", "schema", "--help"]
12+
mocker.patch.object(sys, "argv", testargs)
13+
with pytest.raises(SystemExit):
14+
cli.main()
15+
16+
out, _ = capsys.readouterr()
17+
assert "show commit schema" in str(out).replace("\n", " ")

tests/commands/test_version_command.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import pytest
55
from pytest_mock import MockerFixture
66

7-
from commitizen import commands
7+
from commitizen import cli, commands
88
from commitizen.__version__ import __version__
99
from commitizen.config.base_config import BaseConfig
1010

@@ -106,3 +106,18 @@ def test_version_use_version_provider(
106106
get_provider.assert_called_once()
107107
mock.get_version.assert_called_once()
108108
mock.set_version.assert_not_called()
109+
110+
111+
def test_version_command_shows_description_when_use_help_option(
112+
mocker: MockerFixture, capsys
113+
):
114+
testargs = ["cz", "version", "--help"]
115+
mocker.patch.object(sys, "argv", testargs)
116+
with pytest.raises(SystemExit):
117+
cli.main()
118+
119+
out, _ = capsys.readouterr()
120+
assert (
121+
"get the version of the installed commitizen or the current project"
122+
" (default: installed commitizen)"
123+
) in str(out).replace("\n", " ")

0 commit comments

Comments
 (0)