6
6
import argparse
7
7
8
8
from klpbuild .klplib .utils import ARCHS
9
+ from klpbuild .klplib .plugins import register_plugins_argparser
9
10
10
-
11
- def create_parser () -> argparse .ArgumentParser :
12
- parentparser = argparse .ArgumentParser (add_help = False )
11
+ def add_arg_lp_name (parentparser , mandatory = True ):
13
12
parentparser .add_argument (
14
13
"-n" ,
15
14
"--name" ,
16
15
type = str ,
17
- required = True ,
16
+ required = mandatory ,
18
17
help = "The livepatch name. This will be the directory name of the "
19
18
"resulting livepatches." ,
20
19
)
21
- parentparser .add_argument ("--filter" , type = str , help = r"Filter out codestreams using a regex. Example: 15\.3u[0-9]+" )
22
20
23
- parser = argparse .ArgumentParser (add_help = False )
24
- sub = parser .add_subparsers (dest = "cmd" )
25
21
26
- setup = sub .add_parser ("setup" , parents = [parentparser ])
22
+ def add_arg_lp_filter (parentparser , mandatory = False ):
23
+ parentparser .add_argument (
24
+ "--filter" ,
25
+ type = str ,
26
+ required = mandatory ,
27
+ dest = "lp_filter" ,
28
+ help = r"Filter out codestreams using a regex. Example: 15\.3u[0-9]+"
29
+ )
30
+
31
+
32
+ def create_parser () -> argparse .ArgumentParser :
33
+ parentparser = argparse .ArgumentParser (add_help = True )
34
+ sub = parentparser .add_subparsers (dest = "cmd" )
35
+
36
+ parentparser .add_argument (
37
+ "-v" ,
38
+ "--verbose" ,
39
+ action = "store_true" ,
40
+ help = "Produce more verbose output"
41
+ )
42
+
43
+ register_plugins_argparser (sub )
44
+
45
+ # NOTE: all the code below should be gone when all the module will be
46
+ # converted into plugins
47
+ setup = sub .add_parser ("setup" )
48
+ add_arg_lp_name (setup )
49
+ add_arg_lp_filter (setup )
27
50
setup .add_argument ("--cve" , type = str , help = "SLE specific. The CVE assigned to this livepatch" )
28
51
setup .add_argument ("--conf" , type = str , required = True , help = "The kernel CONFIG used to be build the livepatch" )
29
52
setup .add_argument (
@@ -71,9 +94,10 @@ def create_parser() -> argparse.ArgumentParser:
71
94
nargs = "+" ,
72
95
help = "SLE specific. Supported architectures for this livepatch" ,
73
96
)
74
- setup .add_argument ("--skips" , help = "List of codestreams to filter out" )
75
97
76
- check_inline = sub .add_parser ("check-inline" , parents = [parentparser ])
98
+ check_inline = sub .add_parser ("check-inline" )
99
+ add_arg_lp_name (check_inline )
100
+ add_arg_lp_filter (check_inline )
77
101
check_inline .add_argument (
78
102
"--codestream" ,
79
103
type = str ,
@@ -94,7 +118,9 @@ def create_parser() -> argparse.ArgumentParser:
94
118
help = "Symbol to be found" ,
95
119
)
96
120
97
- extract_opts = sub .add_parser ("extract" , parents = [parentparser ])
121
+ extract_opts = sub .add_parser ("extract" )
122
+ add_arg_lp_name (extract_opts )
123
+ add_arg_lp_filter (extract_opts )
98
124
extract_opts .add_argument (
99
125
"--avoid-ext" ,
100
126
nargs = "+" ,
@@ -107,49 +133,52 @@ def create_parser() -> argparse.ArgumentParser:
107
133
extract_opts .add_argument (
108
134
"--apply-patches" , action = "store_true" , help = "Apply patches found by get-patches subcommand, if they exist"
109
135
)
110
- diff_opts = sub . add_parser ( "cs-diff" , parents = [ parentparser ])
111
- diff_opts . add_argument (
112
- "--cs" , nargs = 2 , type = str , required = True , help = "SLE specific. Apply diff on two different codestreams"
113
- )
136
+
137
+ diff_opts = sub . add_parser ( "cs-diff" )
138
+ add_arg_lp_name ( diff_opts )
139
+ add_arg_lp_filter ( diff_opts )
114
140
115
141
fmt = sub .add_parser (
116
- "format-patches" , parents = [ parentparser ], help = "SLE specific. Extract patches from kgraft-patches"
142
+ "format-patches" , help = "SLE specific. Extract patches from kgraft-patches"
117
143
)
144
+ add_arg_lp_name (fmt )
145
+ add_arg_lp_filter (fmt )
118
146
fmt .add_argument ("-v" , "--version" , type = int , required = True , help = "Version to be added, like vX" )
119
147
120
- patches = sub .add_parser ("get-patches" , parents = [parentparser ])
148
+ patches = sub .add_parser ("get-patches" )
149
+ add_arg_lp_name (patches )
150
+ add_arg_lp_filter (patches )
121
151
patches .add_argument (
122
152
"--cve" , required = True , help = "SLE specific. CVE number to search for related backported patches"
123
153
)
124
154
125
- scan = sub .add_parser ("scan" )
126
- scan .add_argument (
127
- "--cve" , required = True , help = "SLE specific. Shows which codestreams are vulnerable to the CVE"
128
- )
129
- scan .add_argument (
130
- "--conf" , required = False , help = "SLE specific. Helps to check only the codestreams that have this config set."
131
- )
132
155
133
- sub .add_parser ("cleanup" , parents = [parentparser ], help = "SLE specific. Remove livepatch packages from IBS" )
156
+ cleanup = sub .add_parser ("cleanup" , help = "SLE specific. Remove livepatch packages from IBS" )
157
+ add_arg_lp_name (cleanup )
158
+ add_arg_lp_filter (cleanup )
134
159
135
- sub .add_parser (
160
+ test = sub .add_parser (
136
161
"prepare-tests" ,
137
- parents = [parentparser ],
138
162
help = "SLE specific. Download the built tests and check for LP dependencies" ,
139
163
)
164
+ add_arg_lp_name (test )
165
+ add_arg_lp_filter (test )
140
166
141
167
push = sub .add_parser (
142
- "push" , parents = [ parentparser ], help = "SLE specific. Push livepatch packages to IBS to be built"
168
+ "push" , help = "SLE specific. Push livepatch packages to IBS to be built"
143
169
)
170
+ add_arg_lp_name (push )
171
+ add_arg_lp_filter (push )
144
172
push .add_argument ("--wait" , action = "store_true" , help = "Wait until all codestreams builds are finished" )
145
173
146
- status = sub .add_parser ("status" , parents = [parentparser ], help = "SLE specific. Check livepatch build status on IBS" )
174
+ status = sub .add_parser ("status" , help = "SLE specific. Check livepatch build status on IBS" )
175
+ add_arg_lp_name (status )
176
+ add_arg_lp_filter (status )
147
177
status .add_argument ("--wait" , action = "store_true" , help = "Wait until all codestreams builds are finished" )
148
178
149
- log = sub .add_parser ("log" , parents = [parentparser ], help = "SLE specific. Get build log from IBS" )
150
- log .add_argument ("--cs" , type = str , required = True , help = "The codestream to get the log from" )
179
+ log = sub .add_parser ("log" , help = "SLE specific. Get build log from IBS" )
180
+ add_arg_lp_name (log )
181
+ add_arg_lp_filter (log , mandatory = True )
151
182
log .add_argument ("--arch" , type = str , default = "x86_64" , choices = ARCHS , help = "Build architecture" )
152
183
153
- return parser
154
-
155
-
184
+ return parentparser
0 commit comments