Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e4840a0

Browse files
committed
refactor: added commands folder, better integration with decli
1 parent aa44a92 commit e4840a0

21 files changed

+254
-118
lines changed

‎commitizen/__init__.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import logging
22
import logging.config
3+
from colorama import init
34
from commitizen.cz.base import BaseCommitizen
45

6+
7+
init()
8+
9+
510
LOGGING = {
611
"version": 1,
712
"disable_existing_loggers": True,

‎commitizen/application.py‎

Lines changed: 0 additions & 34 deletions
This file was deleted.

‎commitizen/cli.py‎

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
import sys
44
import logging
55
import argparse
6+
import warnings
67
from decli import cli
78
from pathlib import Path
89
from configparser import RawConfigParser, NoSectionError
9-
from commitizen.application import Application
10-
from commitizen import deafults
10+
from commitizen import deafults, commands, out
11+
from commitizen.__version__ import __version__
1112

1213

1314
logger = logging.getLogger(__name__)
@@ -21,11 +22,7 @@
2122
"formatter_class": argparse.RawDescriptionHelpFormatter,
2223
"arguments": [
2324
{"name": "--debug", "action": "store_true", "help": "use debug mode"},
24-
{
25-
"name": ["-n", "--name"],
26-
"default": deafults.NAME,
27-
"help": "use the given commitizen",
28-
},
25+
{"name": ["-n", "--name"], "help": "use the given commitizen"},
2926
{
3027
"name": ["--version"],
3128
"action": "store_true",
@@ -38,28 +35,24 @@
3835
{
3936
"name": "ls",
4037
"help": "show available commitizens",
41-
"func": lambdaapp: app.detected_cz,
38+
"func": commands.ListCz,
4239
},
4340
{
4441
"name": ["commit", "c"],
4542
"help": "create new commit",
46-
"func": lambdaapp: app.cz.run,
43+
"func": commands.Commit,
4744
},
4845
{
4946
"name": "example",
5047
"help": "show commit example",
51-
"func": lambdaapp: app.cz.show_example,
48+
"func": commands.Example,
5249
},
5350
{
5451
"name": "info",
5552
"help": "show information about the cz",
56-
"func": lambda app: app.cz.show_info,
57-
},
58-
{
59-
"name": "schema",
60-
"help": "show commit schema",
61-
"func": lambda app: app.cz.show_schema,
53+
"func": commands.Info,
6254
},
55+
{"name": "schema", "help": "show commit schema", "func": commands.Schema},
6356
],
6457
},
6558
}
@@ -106,16 +99,19 @@ def main():
10699
raise SystemExit(1)
107100

108101
args = parser.parse_args()
109-
app = Application(**config)
110102

111103
if args.name:
112-
app.name=args.name
104+
config.update({"name": args.name})
113105

114106
if args.debug:
107+
warnings.warn(
108+
"Debug will be deprecated in next major version. "
109+
"Please remove it from your scripts"
110+
)
115111
logging.getLogger("commitizen").setLevel(logging.DEBUG)
116112

117113
if args.version:
118-
logger.info(app.version)
119-
sys.exit(0)
114+
out.line(__version__)
115+
raiseSystemExit()
120116

121-
args.func(app)(args)
117+
args.func(config)(args)

‎commitizen/commands/__init__.py‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from .commit import Commit
2+
from .example import Example
3+
from .info import Info
4+
from .list_cz import ListCz
5+
from .schema import Schema
6+
7+
__all__ = ("Commit", "Example", "Info", "ListCz", "Schema")

‎commitizen/commands/commit.py‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from commitizen import factory
2+
3+
4+
class Commit:
5+
"""Show prompt for the user to create a guided commit."""
6+
7+
def __init__(self, config: dict):
8+
self.config: dict = config
9+
self.cz = factory.commiter_factory(self.config)
10+
11+
def __call__(self, *args, **kwargs):
12+
self.cz.run(*args, **kwargs)

‎commitizen/commands/example.py‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from commitizen import factory
2+
3+
4+
class Example:
5+
"""Show an example so people understands the rules."""
6+
7+
def __init__(self, config: dict):
8+
self.config: dict = config
9+
self.cz = factory.commiter_factory(self.config)
10+
11+
def __call__(self, *args, **kwargs):
12+
self.cz.show_example()

‎commitizen/commands/info.py‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from commitizen import factory
2+
3+
4+
class Info:
5+
"""Show in depth explanation of your rules."""
6+
7+
def __init__(self, config: dict):
8+
self.config: dict = config
9+
self.cz = factory.commiter_factory(self.config)
10+
11+
def __call__(self, *args, **kwargs):
12+
self.cz.show_info()

‎commitizen/commands/list_cz.py‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from commitizen import out
2+
from commitizen.cz import registry
3+
4+
5+
class ListCz:
6+
"""List currently installed rules."""
7+
8+
def __init__(self, config: dict):
9+
self.config: dict = config
10+
11+
def __call__(self, *args, **kwargs):
12+
out.write("\n".join(registry.keys()))

‎commitizen/commands/schema.py‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from commitizen import factory
2+
3+
4+
class Schema:
5+
"""Show structure of the rule."""
6+
7+
def __init__(self, config: dict):
8+
self.config: dict = config
9+
self.cz = factory.commiter_factory(self.config)
10+
11+
def __call__(self, *args, **kwargs):
12+
self.cz.show_schema()

‎commitizen/cz/__init__.py‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,11 @@
33
from commitizen.cz.conventional_commits import ConventionalCommitsCz
44
from commitizen.cz.jira import JiraSmartCz
55

6-
7-
registry = {
6+
registry= {"cz_conventional_commits": ConventionalCommitsCz, "cz_jira": JiraSmartCz}
7+
plugins = {
88
name: importlib.import_module(name).discover_this
99
for finder, name, ispkg in pkgutil.iter_modules()
1010
if name.startswith("cz_")
1111
}
1212

13-
registry.update(
14-
{"cz_conventional_commits": ConventionalCommitsCz, "cz_jira": JiraSmartCz}
15-
)
13+
registry.update(plugins)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /