@@ -42,17 +42,14 @@ def main() -> None:
4242 parser = argparse .ArgumentParser ()
4343
4444 parser .add_argument ("--arch" , dest = "arch" )
45- parser .add_argument ("--cname" , dest = "cname" )
45+ parser .add_argument ("--cname" , dest = "cname" , required = True )
4646 parser .add_argument ("--commit" , dest = "commit" )
4747 parser .add_argument ("--feature-dir" , default = "features" )
48+ parser .add_argument ("--release-file" , dest = "release_file" )
4849 parser .add_argument ("--default-arch" , dest = "default_arch" )
4950 parser .add_argument ("--default-version" , dest = "default_version" )
5051 parser .add_argument ("--version" , dest = "version" )
5152
52- parser .add_argument (
53- "--features" , type = lambda arg : set ([f for f in arg .split ("," ) if f ])
54- )
55-
5653 parser .add_argument (
5754 "--ignore" ,
5855 dest = "ignore" ,
@@ -64,9 +61,9 @@ def main() -> None:
6461
6562 args = parser .parse_args ()
6663
67- assert bool (args .features ) or bool (
68- args .cname
69- ), "Please provide either `--features ` or `--cname ` argument"
64+ assert bool (args .feature_dir ) or bool (
65+ args .release_file
66+ ), "Please provide either `--feature_dir ` or `--release_file ` argument"
7067
7168 arch = args .arch
7269 flavor = None
@@ -99,6 +96,9 @@ def main() -> None:
9996 args .cname , arch = arch , commit_hash = commit_id_or_hash , version = version
10097 )
10198
99+ if args .release_file is not None :
100+ cname .load_from_release_file (args .release_file )
101+
102102 arch = cname .arch
103103 flavor = cname .flavor
104104 commit_id_or_hash = cname .commit_id
@@ -122,53 +122,22 @@ def main() -> None:
122122
123123 feature_dir_name = path .basename (args .feature_dir )
124124
125- additional_filter_func = lambda node : node not in args .ignore
126-
127125 if args .type == "arch" :
128126 print (arch )
129- elif args .type in ("cname_base" , "cname" , "graph" ):
130- graph = Parser (gardenlinux_root , feature_dir_name ).filter (
131- flavor , additional_filter_func = additional_filter_func
132- )
133-
134- sorted_features = Parser .sort_graph_nodes (graph )
135- minimal_feature_set = get_minimal_feature_set (graph )
136-
137- sorted_minimal_features = sort_subset (minimal_feature_set , sorted_features )
138-
139- cname_base = get_cname_base (sorted_minimal_features )
140-
141- if args .type == "cname_base" :
142- print (cname_base )
143- elif args .type == "cname" :
144- cname = flavor
145-
146- if arch is not None :
147- cname += f"-{ arch } "
148-
149- if commit_id_or_hash is not None :
150- cname += f"-{ version } -{ commit_id_or_hash [:8 ]} "
151-
152- print (cname )
153- elif args .type == "graph" :
154- print (graph_as_mermaid_markup (flavor , graph ))
155- elif args .type == "features" :
156- print (
157- Parser (gardenlinux_root , feature_dir_name ).filter_as_string (
158- flavor , additional_filter_func = additional_filter_func
159- )
160- )
161- elif args .type in ("flags" , "elements" , "platforms" ):
162- features_by_type = Parser (gardenlinux_root , feature_dir_name ).filter_as_dict (
163- flavor , additional_filter_func = additional_filter_func
164- )
165-
166- if args .type == "platforms" :
167- print ("," .join (features_by_type ["platform" ]))
168- elif args .type == "elements" :
169- print ("," .join (features_by_type ["element" ]))
170- elif args .type == "flags" :
171- print ("," .join (features_by_type ["flag" ]))
127+ elif args .type in (
128+ "cname_base" ,
129+ "cname" ,
130+ "elements" ,
131+ "features" ,
132+ "flags" ,
133+ "graph" ,
134+ "platforms" ,
135+ ):
136+ if args .type == "graph" or len (args .ignore ) > 1 :
137+ features_parser = Parser (gardenlinux_root , feature_dir_name )
138+ print_output_from_features_parser (args .type , features_parser , flavor , args .ignore )
139+ else :
140+ print_output_from_cname (args .type , cname )
172141 elif args .type == "commit_id" :
173142 print (commit_id_or_hash [:8 ])
174143 elif args .type == "version" :
@@ -255,6 +224,95 @@ def graph_as_mermaid_markup(flavor: str, graph: Any) -> str:
255224 return markup
256225
257226
227+ def print_output_from_features_parser (
228+ output_type : str , parser : Parser , flavor : str , ignores_list : set
229+ ) -> None :
230+ """
231+ Prints output to stdout based on the given features parser and parameters.
232+
233+ :param output_type: Output type
234+ :param parser: Features parser
235+ :param flavor: Flavor
236+ :param ignores_list: Features to ignore
237+
238+ :since: 0.11.0
239+ """
240+
241+ additional_filter_func = lambda node : node not in ignores_list
242+
243+ if output_type == "features" :
244+ print (
245+ parser .filter_as_string (
246+ flavor , additional_filter_func = additional_filter_func
247+ )
248+ )
249+ elif (output_type in "platforms" , "elements" , "flags" ):
250+ features_by_type = parser .filter_as_dict (
251+ flavor , additional_filter_func = additional_filter_func
252+ )
253+
254+ if output_type == "platforms" :
255+ print ("," .join (features_by_type ["platform" ]))
256+ elif output_type == "elements" :
257+ print ("," .join (features_by_type ["element" ]))
258+ elif output_type == "flags" :
259+ print ("," .join (features_by_type ["flag" ]))
260+ else :
261+ graph = parser .filter (flavor , additional_filter_func = additional_filter_func )
262+
263+ sorted_features = Parser .sort_graph_nodes (graph )
264+ minimal_feature_set = get_minimal_feature_set (graph )
265+
266+ sorted_minimal_features = sort_subset (minimal_feature_set , sorted_features )
267+
268+ cname_base = get_cname_base (sorted_minimal_features )
269+
270+ if output_type == "cname_base" :
271+ print (cname_base )
272+ elif output_type == "cname" :
273+ cname = flavor
274+
275+ if arch is not None :
276+ cname += f"-{ arch } "
277+
278+ if commit_id_or_hash is not None :
279+ cname += f"-{ version } -{ commit_id_or_hash [:8 ]} "
280+
281+ print (cname )
282+ if output_type == "platforms" :
283+ print ("," .join (features_by_type ["platform" ]))
284+ elif output_type == "elements" :
285+ print ("," .join (features_by_type ["element" ]))
286+ elif output_type == "flags" :
287+ print ("," .join (features_by_type ["flag" ]))
288+ elif output_type == "graph" :
289+ print (graph_as_mermaid_markup (flavor , graph ))
290+
291+
292+ def print_output_from_cname (output_type : str , cname_instance : CName ) -> None :
293+ """
294+ Prints output to stdout based on the given CName instance.
295+
296+ :param output_type: Output type
297+ :param cname_instance: CName instance
298+
299+ :since: 0.11.0
300+ """
301+
302+ if output_type == "cname_base" :
303+ print (cname_instance .flavor )
304+ elif output_type == "cname" :
305+ print (cname_instance .cname )
306+ elif output_type == "platforms" :
307+ print (cname_instance .feature_set_platform )
308+ elif output_type == "elements" :
309+ print (cname_instance .feature_set_element )
310+ elif output_type == "features" :
311+ print (cname_instance .feature_set )
312+ elif output_type == "flags" :
313+ print (cname_instance .feature_set_flag )
314+
315+
258316def sort_subset (input_set : Set [str ], order_list : List [str ]) -> List [str ]:
259317 """
260318 Returns items from `order_list` if given in `input_set`.
0 commit comments