@@ -40,17 +40,14 @@ def main() -> None:
4040 parser = argparse .ArgumentParser ()
4141
4242 parser .add_argument ("--arch" , dest = "arch" )
43- parser .add_argument ("--cname" , dest = "cname" )
43+ parser .add_argument ("--cname" , dest = "cname" , required = True )
4444 parser .add_argument ("--commit" , dest = "commit" )
4545 parser .add_argument ("--feature-dir" , default = "features" )
46+ parser .add_argument ("--release-file" , dest = "release_file" )
4647 parser .add_argument ("--default-arch" , dest = "default_arch" )
4748 parser .add_argument ("--default-version" , dest = "default_version" )
4849 parser .add_argument ("--version" , dest = "version" )
4950
50- parser .add_argument (
51- "--features" , type = lambda arg : set ([f for f in arg .split ("," ) if f ])
52- )
53-
5451 parser .add_argument (
5552 "--ignore" ,
5653 dest = "ignore" ,
@@ -62,9 +59,9 @@ def main() -> None:
6259
6360 args = parser .parse_args ()
6461
65- assert bool (args .features ) or bool (
66- args .cname
67- ), "Please provide either `--features ` or `--cname ` argument"
62+ assert bool (args .feature_dir ) or bool (
63+ args .release_file
64+ ), "Please provide either `--feature_dir ` or `--release_file ` argument"
6865
6966 arch = args .arch
7067 flavor = None
@@ -97,15 +94,14 @@ def main() -> None:
9794 args .cname , arch = arch , commit_hash = commit_id_or_hash , version = version
9895 )
9996
97+ if args .release_file is not None :
98+ cname .load_from_release_file (args .release_file )
99+
100100 arch = cname .arch
101101 flavor = cname .flavor
102102 commit_id_or_hash = cname .commit_id
103103 version = cname .version
104104
105- _ = Parser .get_cname_as_feature_set (flavor )
106- else :
107- _ = args .features
108-
109105 if arch is None or arch == "" and (args .type in ("cname" , "arch" )):
110106 raise RuntimeError (
111107 "Architecture could not be determined and no default architecture set"
@@ -120,53 +116,25 @@ def main() -> None:
120116
121117 feature_dir_name = path .basename (args .feature_dir )
122118
123- additional_filter_func = lambda node : node not in args .ignore
124-
125119 if args .type == "arch" :
126120 print (arch )
127- elif args .type in ("cname_base" , "cname" , "graph" ):
128- graph = Parser (gardenlinux_root , feature_dir_name ).filter (
129- flavor , additional_filter_func = additional_filter_func
130- )
131-
132- sorted_features = Parser .sort_graph_nodes (graph )
133- minimal_feature_set = get_minimal_feature_set (graph )
134-
135- sorted_minimal_features = sort_subset (minimal_feature_set , sorted_features )
136-
137- cname_base = get_cname_base (sorted_minimal_features )
138-
139- if args .type == "cname_base" :
140- print (cname_base )
141- elif args .type == "cname" :
142- cname = flavor
143-
144- if arch is not None :
145- cname += f"-{ arch } " # type: ignore - None check is carried out.
146-
147- if commit_id_or_hash is not None :
148- cname += f"-{ version } -{ commit_id_or_hash [:8 ]} " # type: ignore - None check is carried out.
121+ elif args .type in (
122+ "cname_base" ,
123+ "cname" ,
124+ "elements" ,
125+ "features" ,
126+ "flags" ,
127+ "graph" ,
128+ "platforms" ,
129+ ):
130+ if args .type == "graph" or len (args .ignore ) > 1 :
131+ features_parser = Parser (gardenlinux_root , feature_dir_name )
149132
150- print (cname )
151- elif args .type == "graph" :
152- print (graph_as_mermaid_markup (flavor , graph ))
153- elif args .type == "features" :
154- print (
155- Parser (gardenlinux_root , feature_dir_name ).filter_as_string (
156- flavor , additional_filter_func = additional_filter_func
133+ print_output_from_features_parser (
134+ args .type , features_parser , flavor , args .ignore
157135 )
158- )
159- elif args .type in ("flags" , "elements" , "platforms" ):
160- features_by_type = Parser (gardenlinux_root , feature_dir_name ).filter_as_dict (
161- flavor , additional_filter_func = additional_filter_func
162- )
163-
164- if args .type == "platforms" :
165- print ("," .join (features_by_type ["platform" ]))
166- elif args .type == "elements" :
167- print ("," .join (features_by_type ["element" ]))
168- elif args .type == "flags" :
169- print ("," .join (features_by_type ["flag" ]))
136+ else :
137+ print_output_from_cname (args .type , cname )
170138 elif args .type == "commit_id" :
171139 print (commit_id_or_hash [:8 ])
172140 elif args .type == "version" :
@@ -256,6 +224,95 @@ def graph_as_mermaid_markup(flavor: str | None, graph: Any) -> str:
256224 return markup
257225
258226
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+
259316def sort_subset (input_set : Set [str ], order_list : List [str ]) -> List [str ]:
260317 """
261318 Returns items from `order_list` if given in `input_set`.
0 commit comments