@@ -1245,6 +1245,27 @@ def _usage_error(parser: argparse.ArgumentParser, message: str) -> int:
12451245 return EX_USAGE
12461246
12471247
1248+ def _select_builtin_dictionary (builtin_option : str ) -> list [str ]:
1249+ use = sorted (set (builtin_option .split ("," )))
1250+ if "all" in use :
1251+ use = [u for u in use if u != "all" ] + [
1252+ builtin [0 ] for builtin in _builtin_dictionaries
1253+ ]
1254+ use = sorted (set (use ))
1255+
1256+ use_dictionaries = []
1257+ for u in use :
1258+ for builtin in _builtin_dictionaries :
1259+ if builtin [0 ] == u :
1260+ use_dictionaries .append (
1261+ os .path .join (_data_root , f"dictionary{ builtin [2 ]} .txt" )
1262+ )
1263+ break
1264+ else :
1265+ raise KeyError (u )
1266+ return use_dictionaries
1267+
1268+
12481269def main (* args : str ) -> int :
12491270 """Contains flow control"""
12501271 try :
@@ -1338,25 +1359,13 @@ def main(*args: str) -> int:
13381359 use_dictionaries = []
13391360 for dictionary in dictionaries :
13401361 if dictionary == "-" :
1341- # figure out which builtin dictionaries to use
1342- use = sorted (set (options .builtin .split ("," )))
1343- if "all" in use :
1344- use = [u for u in use if u != "all" ] + [
1345- builtin [0 ] for builtin in _builtin_dictionaries
1346- ]
1347- use = sorted (set (use ))
1348- for u in use :
1349- for builtin in _builtin_dictionaries :
1350- if builtin [0 ] == u :
1351- use_dictionaries .append (
1352- os .path .join (_data_root , f"dictionary{ builtin [2 ]} .txt" )
1353- )
1354- break
1355- else :
1356- return _usage_error (
1357- parser ,
1358- f"ERROR: Unknown builtin dictionary: { u } " ,
1359- )
1362+ try :
1363+ use_dictionaries .extend (_select_builtin_dictionary (options .builtin ))
1364+ except KeyError as e :
1365+ return _usage_error (
1366+ parser ,
1367+ f"ERROR: Unknown builtin dictionary: { e .args [0 ]} " ,
1368+ )
13601369 else :
13611370 if not os .path .isfile (dictionary ):
13621371 return _usage_error (
0 commit comments