forked from commitizen-tools/commitizen
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.py
More file actions
146 lines (130 loc) · 4.47 KB
/
cli.py
File metadata and controls
146 lines (130 loc) · 4.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
import io
import os
import sys
import logging
import argparse
import warnings
from decli import cli
from pathlib import Path
from configparser import RawConfigParser, NoSectionError
from commitizen import defaults, commands, out, config
from commitizen.__version__ import __version__
logger = logging.getLogger(__name__)
data = {
"prog": "cz",
"description": (
"Commitizen is a cli tool to generate conventional commits.\n"
"For more information about the topic go to "
"https://conventionalcommits.org/"
),
"formatter_class": argparse.RawDescriptionHelpFormatter,
"arguments": [
{"name": "--debug", "action": "store_true", "help": "use debug mode"},
{"name": ["-n", "--name"], "help": "use the given commitizen"},
{
"name": ["--version"],
"action": "store_true",
"help": "get the version of the installed commitizen",
},
],
"subcommands": {
"title": "commands",
"commands": [
{
"name": "ls",
"help": "show available commitizens",
"func": commands.ListCz,
},
{
"name": ["commit", "c"],
"help": "create new commit",
"func": commands.Commit,
},
{
"name": "example",
"help": "show commit example",
"func": commands.Example,
},
{
"name": "info",
"help": "show information about the cz",
"func": commands.Info,
},
{"name": "schema", "help": "show commit schema", "func": commands.Schema},
{
"name": "bump",
"help": "bump semantic version based on the git log",
"func": commands.Bump,
"arguments": [
{
"name": "--dry-run",
"action": "store_true",
"help": "show output to stdout, no commit, no modified files",
},
{
"name": "--tag-format",
"help": (
"format used to tag the commmit and read it, "
"use it in existing projects, "
"wrap around simple quotes."
),
},
{
"name": ["--prerelease", "-pr"],
"help": "choose type of prerelease",
"choices": ["alpha", "beta", "rc"],
},
{
"name": ["--increment"],
"help": "manually specify the desired increment",
"choices": ["MAJOR", "MINOR", "PATCH"],
},
],
},
],
},
}
def load_cfg():
settings = {"name": defaults.name}
config = RawConfigParser("")
home = str(Path.home())
config_file = ".cz"
global_cfg = os.path.join(home, config_file)
# load cfg from current project
configs = ["setup.cfg", ".cz.cfg", config_file, global_cfg]
for cfg in configs:
if not os.path.exists(config_file) and os.path.exists(cfg):
config_file = cfg
config_file_exists = os.path.exists(config_file)
if config_file_exists:
logger.debug('Reading file "%s"', config_file)
config.read_file(io.open(config_file, "rt", encoding="utf-8"))
log_config = io.StringIO()
config.write(log_config)
try:
settings.update(dict(config.items("commitizen")))
break
except NoSectionError:
# The file does not have commitizen section
continue
return settings
def main():
conf = config.read_cfg()
parser = cli(data)
# Show help if no arg provided
if len(sys.argv) == 1:
parser.print_help(sys.stderr)
raise SystemExit()
args = parser.parse_args()
if args.name:
conf.update({"name": args.name})
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))()