-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathcommands.py
More file actions
234 lines (204 loc) · 5.66 KB
/
commands.py
File metadata and controls
234 lines (204 loc) · 5.66 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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
# Copyright © 2025 CloudBlue. All rights reserved.
import os
import click
from connect.cli.core import group
from connect.cli.core.config import pass_config
from connect.cli.plugins.project.extension.helpers import (
bootstrap_extension_project,
bump_runner_extension_project,
deploy_extension_project,
validate_extension_project,
)
from connect.cli.plugins.project.report.helpers import (
add_report,
bootstrap_report_project,
validate_report_project,
)
class Mutex(click.Option):
def __init__(self, *args, **kwargs):
self.conflict_with: list = kwargs.pop('conflict_with')
assert self.conflict_with, "'conflict_with' parameter required"
help_str = kwargs.get('help', '')
help_str += f' This option is mutually exclusive with {", ".join(self.conflict_with)}.'
kwargs['help'] = help_str.strip()
super(Mutex, self).__init__(*args, **kwargs)
def handle_parse_result(self, ctx, opts, args):
current_opt: bool = self.name in opts
for mutex_opt in self.conflict_with:
if mutex_opt in opts:
if current_opt:
raise click.UsageError(
f'Illegal usage: options {self.name} and {mutex_opt} are mutually exclusive.',
)
else:
self.prompt = None
return super(Mutex, self).handle_parse_result(ctx, opts, args)
@group(name='project', short_help='Manage project definitions.')
def grp_project():
pass # pragma: no cover
# REPORTS
@grp_project.group(
name='report',
short_help='Manage report projects.',
)
def grp_project_report():
pass # pragma: no cover
@grp_project_report.command(
name='bootstrap',
short_help='Bootstrap new report project.',
)
@click.option(
'--output-dir',
'-o',
default=os.getcwd(),
type=click.Path(exists=False, file_okay=False, dir_okay=True),
required=True,
help='Directory where the new report project will be created.',
)
@click.option(
'--force-overwrite',
'-f',
is_flag=True,
help='Overwrite the destination project directory if exists.',
default=False,
)
def cmd_bootstrap_report_project(output_dir, force_overwrite):
bootstrap_report_project(output_dir, force_overwrite)
@grp_project_report.command(
name='validate',
short_help='Validate given report project.',
)
@click.option(
'--project-dir',
'-p',
required=True,
type=click.Path(exists=True, file_okay=False, dir_okay=True),
help='Project directory.',
)
def cmd_validate_report_project(project_dir):
validate_report_project(project_dir)
@grp_project_report.command(
name='add',
short_help='Add new report to the given project.',
)
@click.option(
'--project-dir',
'-p',
required=True,
type=click.Path(exists=True, file_okay=False, dir_okay=True),
help='Project directory.',
)
@click.option(
'--package-name',
'-n',
default='reports',
help='Package directory.',
)
def cmd_add_report(project_dir, package_name):
add_report(project_dir, package_name)
# EXTENSION AS A SERVICE
@grp_project.group(
name='extension',
short_help='Manage extension projects.',
)
def grp_project_extension():
pass # pragma: no cover
@grp_project_extension.command(
name='bootstrap',
short_help='Bootstrap new extension project.',
)
@click.option(
'--output-dir',
'-o',
default=os.getcwd(),
type=click.Path(exists=False, file_okay=False, dir_okay=True),
required=False,
help='Directory where the new extension project will be created.',
)
@click.option(
'--force-overwrite',
'-f',
is_flag=True,
help='Overwrite the destination project directory if exists.',
default=False,
)
@click.option(
'--save-answers',
'-s',
default=None,
type=click.Path(exists=False, file_okay=True, dir_okay=False),
required=False,
help='Path to JSON file where to save wizard answers.',
cls=Mutex,
conflict_with=['load_answers'],
)
@click.option(
'--load-answers',
'-l',
default=None,
type=click.Path(exists=True, file_okay=True, dir_okay=False),
required=False,
help='Path to JSON file from where load wizard answers.',
cls=Mutex,
conflict_with=['save_answers'],
)
@pass_config
def cmd_bootstrap_extension_project(
config,
output_dir,
force_overwrite,
save_answers,
load_answers,
):
bootstrap_extension_project(
config,
output_dir,
force_overwrite,
save_answers,
load_answers,
)
@grp_project_extension.command(
name='validate',
short_help='Validate given extension project.',
)
@click.argument(
'project_dir',
metavar='PROJECT_DIR',
nargs=1,
required=True,
type=click.Path(exists=True, file_okay=False, dir_okay=True),
)
@pass_config
def cmd_validate_extension_project(config, project_dir):
validate_extension_project(config, project_dir)
@grp_project_extension.command(
name='bump',
short_help='Update runner version to the latest one.',
)
@click.option(
'--project-dir',
'-p',
required=True,
type=click.Path(exists=True, file_okay=False, dir_okay=True),
help='Project directory.',
)
def cmd_bump_extension_project(project_dir):
bump_runner_extension_project(project_dir)
@grp_project_extension.command(
name='deploy',
short_help='Deploy extension.',
)
@click.argument('repo', metavar='repo', nargs=1, required=True)
@click.option(
'--tag',
'-t',
required=False,
default=None,
type=str,
help='Repository tag.',
)
@pass_config
def cmd_deploy_extension(config, repo, tag):
deploy_extension_project(config, repo, tag)
def get_group():
return grp_project