77from pathlib import Path
88from typing import Any
99
10- from cli2gui .types import ParserType , SEP
10+ from cli2gui .types import SEP , ParserType
1111
1212
13- def processValue (key :str , value :str ) -> tuple [str , Any ]:
13+ def processValue (key : str , value : str ) -> tuple [str , Any ]:
1414 if SEP not in key :
1515 return key , value or None
1616 key , _type = key .split (SEP , maxsplit = 1 )
1717 if len (str (value )) == 0 or value is None :
18- return key ,None
18+ return key , None
1919 if _type == "ItemType.Bool" :
20- return key ,bool (value )
20+ return key , bool (value )
2121 if _type == "ItemType.File" :
22- return key ,open (value , encoding = "utf-8" )
22+ return key , open (value , encoding = "utf-8" )
2323 if _type == "ItemType.Path" :
24- return key ,Path (value )
24+ return key , Path (value )
2525 if _type == "ItemType.Int" :
26- return key ,int (value )
26+ return key , int (value )
2727 if _type == "ItemType.Text" :
28- return key ,value
28+ return key , value
2929 if _type == "ItemType.Float" :
30- return key ,float (value )
30+ return key , float (value )
3131 if _type == "ItemType.List" :
32- return key ,value
32+ return key , value
3333 if _type == "ItemType.Tuple" :
34- return key ,value
34+ return key , value
3535 if _type == "ItemType.DateTime" :
36- return key ,value
36+ return key , value
37+
38+ return key , value
3739
38- return key ,value
3940
4041def argparseFormat (values : dict [str , Any ]) -> argparse .Namespace :
4142 """Format args for argparse."""
4243 args = {}
4344 for key in values :
44- key , value = processValue (key , values [key ])
45- args [key ] = value
45+ cleankey , value = processValue (key , values [key ])
46+ args [cleankey ] = value
4647 return argparse .Namespace (** args )
4748
4849
4950def optparseFormat (values : dict [str , Any ]) -> tuple [optparse .Values , list [str ]]:
5051 """Format args for optparse."""
5152 args = {}
5253 for key in values :
53- key , value = processValue (key , values [key ])
54- args [key ] = value
54+ cleankey , value = processValue (key , values [key ])
55+ args [cleankey ] = value
5556 return (optparse .Values (args ), [])
5657
5758
5859def getoptFormat (values : dict [str , Any ]) -> tuple [list [Any ], list [Any ]]:
5960 """Format args for getopt."""
60- return ([
61- processValue (key , values [key ])
62- for key in values if values [key ]],
63- []
64- )
61+ return ([processValue (key , values [key ]) for key in values if values [key ]], [])
6562
6663
6764def docoptFormat (values : dict [str , Any ]) -> dict [str , Any ]:
6865 """Format args for docopt."""
6966 import docopt
67+
7068 args = {}
7169 for key in values :
72- key , value = processValue (key , values [key ])
73- args [key ] = value
70+ cleankey , value = processValue (key , values [key ])
71+ args [cleankey ] = value
7472 return docopt .Dict (args )
7573
7674
7775def clickFormat (values : dict [str , Any ]) -> list [Any ]:
7876 """Format args for click."""
7977 args = []
8078 for key in values :
81-
8279 val = str (values [key ])
8380 if not callable (key ) and len (val ) > 0 :
84- key , value = processValue (key , values [key ])
85- args .extend ([key , value ])
81+ cleankey , value = processValue (key , values [key ])
82+ args .extend ([cleankey , value ])
8683 return args
8784
8885
@@ -99,7 +96,6 @@ def argFormat(values: dict[str, Any], argumentParser: str | ParserType) -> Any:
9996 Any: args
10097
10198 """
102- formattedArgs = None
10399 convertMap = {
104100 ParserType .OPTPARSE : optparseFormat ,
105101 ParserType .ARGPARSE : argparseFormat ,
@@ -110,4 +106,4 @@ def argFormat(values: dict[str, Any], argumentParser: str | ParserType) -> Any:
110106 }
111107 if argumentParser in convertMap :
112108 return convertMap [argumentParser ](values )
113- return formattedArgs
109+ return None
0 commit comments