-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcli.py
102 lines (83 loc) ยท 3.55 KB
/
cli.py
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
"""
ๅผๆไปๅบๅๆญฅๅ็บงๅทฅๅ
ท
Precondition:
1. install git
Usage:
trident init [-r ROOT] [-c CONFIG]
trident sync [-r ROOT] [-c CONFIG] [-t TOKEN] [-i]
trident remote [-r ROOT] [-u URL] [-f]
trident version
trident -h
Options:
-h,--help show help menu, ๆพ็คบๅธฎๅฉ่ๅ
-c,--config=CONFIG config file path, ้
็ฝฎๆไปถ [default: sync.yaml]
-r,--root=ROOT root dir, ๆ น็ฎๅฝ [default: .]
-t,--token=TOKEN PR token
-u,--url=URL remote git url, ่ฟ็จๅฐๅ
-f,--force force push, ๅผบๅถๆจ้
-i,--init init first, ๅๆญฅๅๅ
ๅๅงๅ
Example:
trident init
trident sync
trident remote --url=https://github.com/handsfree-work/trident-test-sync
"""
import os
import yaml
from docopt import docopt
from lib.handler.init import InitHandler
from lib.handler.remote import RemoteHandler
from lib.handler.sync import SyncHandler
from lib.logger import logger
from lib.model.config import Config
from lib.util import get_arg
from lib.version import get_version
def cli():
"""
ๅผๆไปๅบๅๆญฅๅ็บงๅทฅๅ
ทๅ
ฅๅฃ
"""
args = docopt(__doc__)
version = get_version()
print(f'''
โโโโโโโโโโโโโโโโ โโโโโโโโโโ โโโโโโโโโโโโ โโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโ
โโโ โโโโโโโโโโโโโโ โโโโโโโโโ โโโโโโ โโโ โโโ
โโโ โโโโโโโโโโโโโโ โโโโโโโโโ โโโโโโโโโโ โโโ
โโโ โโโ โโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโ โโโ
โโโ โโโ โโโโโโโโโโโโโ โโโโโโโโโโโ โโโโโ โโโ
https://github.com/handsfree-work/trident-sync
Don't be stingy with your star ( ่ฏทไธ่ฆๅๅฌไฝ ็star )
Copyright ยฉ 2023 greper@handsfree.work v{version}
''')
root = get_root(args)
if not os.path.exists(root):
os.makedirs(root)
arg_config = get_arg(args, '--config')
config_dict = read_config(arg_config)
os.chdir(root)
if args['remote']:
remote_url = args['--url']
force = args['--force']
RemoteHandler(root, remote_url=remote_url, force=force).handle()
return
token_from_args = get_arg(args, '--token')
config = Config(config_dict)
config.set_default_token(token_from_args)
if args['init']:
InitHandler(root, config).handle()
elif args['sync']:
init_first = get_arg(args, '--init')
if init_first:
logger.info("init first")
InitHandler(root, config).handle()
SyncHandler(root, config).handle()
else:
logger.info(__doc__)
def read_config(arg_config='./sync.yaml'):
config_file = os.path.abspath(f"{arg_config}")
f = open(config_file, 'r', encoding='utf-8')
return yaml.load(f, Loader=yaml.FullLoader)
def get_root(args):
root = get_arg(args, '--root')
return os.path.abspath(root)
if __name__ == '__main__':
cli()