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
|
import os
from sys import argv, stdout, stderr
from . import args_helpers, issue_tracker
help_text = """\
Usage: xpit init
Options:
-h, --help
Print this help text.
"""
class Args:
def __init__(self):
pass
def parse(self) -> bool:
flag_value_map = {
"help|h": 0,
}
res = args_helpers.parse_generic(flag_value_map, argv, 2)
if res is None:
return False
if "help" in res:
stdout.write(help_text)
return False
return True
args = Args()
def main() -> int:
if len(argv) < 2:
stdout.write(help_text)
return 1
if not args.parse():
return 1
if issue_tracker.find_dir(os.getcwd(), suppress_warning=True) is not None:
stderr.write("xpit already initialized\n")
return 1
os.mkdir("issue-tracker")
config_file_path = os.path.join("issue-tracker", "_config.ini")
with open(config_file_path, "wb") as f:
f.write(b"""\
id_format=%Y%m%d_%H%M%S ; `man strftime` for format
allowed_labels=bug,breaking,contributor-friendly,docs,use-case,regression,proposal ; labels that are allowed to be used in issues. (Comma-separated list)
\n""")
stdout.write(f"""\
Successfully initialized at ./issue-tracker.
Configure in {config_file_path}
""")
return 0
|