Skip to content
Merged
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
32 changes: 25 additions & 7 deletions commitizen/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from decli import cli

from commitizen import commands, config, out
from commitizen.__version__ import __version__


logger = logging.getLogger(__name__)
data = {
Expand All @@ -28,6 +28,8 @@
],
"subcommands": {
"title": "commands",
# TODO: Add this constraint back in 2.0
# "required": True,
"commands": [
{
"name": "ls",
Expand Down Expand Up @@ -99,6 +101,11 @@
},
],
},
{
"name": ["version"],
"help": "get the version of the installed commitizen",
"func": commands.Version,
},
],
},
}
Expand All @@ -113,20 +120,31 @@ def main():
parser.print_help(sys.stderr)
raise SystemExit()

args = parser.parse_args()
try:
args = parser.parse_args()
except TypeError:
out.error("Command is required")
raise SystemExit()

if args.name:
conf.update({"name": args.name})

if args.version:
warnings.warn(
"'cz --version' will be deprecated in next major version. "
"Please use 'cz version' command from your scripts"
)
logging.getLogger("commitizen").setLevel(logging.DEBUG)

if args.debug:
warnings.warn(
"Debug will be deprecated in next major version. "
"Please remove it from your scripts"
)
logging.getLogger("commitizen").setLevel(logging.DEBUG)

if args.version:
out.line(__version__)
raise SystemExit()

args.func(conf, vars(args))()
# TODO: This try block can be removed after command is required in 2.0
try:
args.func(conf, vars(args))()
except AttributeError:
out.error("Command is required")
3 changes: 2 additions & 1 deletion commitizen/commands/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
from .info import Info
from .list_cz import ListCz
from .schema import Schema
from .version import Version

__all__ = ("Bump", "Commit", "Example", "Info", "ListCz", "Schema")
__all__ = ("Bump", "Commit", "Example", "Info", "ListCz", "Schema", "Version")
12 changes: 12 additions & 0 deletions commitizen/commands/version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from commitizen import out
from commitizen.__version__ import __version__


class Version:
"""Get the version of the installed commitizen."""

def __init__(self, config: dict, *args):
self.config: dict = config

def __call__(self):
out.write(__version__)
7 changes: 7 additions & 0 deletions tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,10 @@ def test_list_cz():

commands.ListCz(config)()
mocked_write.assert_called_once()


def test_version():
with mock.patch("commitizen.out.write") as mocked_write:

commands.Version(config)()
mocked_write.assert_called_once()