@@ -121,6 +121,51 @@ def convert(self, value, param, ctx):
121121 return None
122122
123123
124+ def _process_args (args : list , string : bool = True ):
125+ """Internal function to parse arguments provided on command line.
126+
127+ :param args: Array of argument values
128+ :param string: True if arguments values are strings, false if argument values are integers
129+
130+ :return Tuple, where the first member is hash of parsed values, and second is boolean flag
131+ indicating if parsing succeeded.
132+ """
133+ kwargs = {}
134+ execute = True
135+ skip_index = None
136+
137+ def _parse_val (arg_name , val ):
138+ if not string :
139+ if "," in val :
140+ val = val .split ("," )
141+ val = [int (v , 0 ) for v in val ]
142+ else :
143+ val = int (val , 0 )
144+ kwargs [arg_name ] = val
145+
146+ for i , arg in enumerate (args ):
147+ if i == skip_index :
148+ continue
149+ arg = arg .strip ()
150+ if "=" in arg :
151+ arg_name , val = arg .split ("=" )
152+ _parse_val (arg_name , val )
153+ else :
154+ arg_name , val = arg , args [i + 1 ]
155+ try :
156+ _parse_val (arg_name , val )
157+ skip_index = i + 1
158+ except TypeError :
159+ click .secho ("Error parsing arguments!" , fg = "yellow" )
160+ execute = False
161+ break
162+ except ValueError :
163+ click .secho ("Error parsing argument" , fg = "yellow" )
164+ execute = False
165+ break
166+ return kwargs , execute
167+
168+
124169def cli (client ): # noqa: C901 pylint: disable=too-complex
125170 """Run client definition."""
126171 use_keys = KeyBindings ()
@@ -142,44 +187,6 @@ def _(event):
142187 buffer = event .cli .current_buffer
143188 buffer .complete_state = None
144189
145- def _process_args (args , string = True ):
146- kwargs = {}
147- execute = True
148- skip_index = None
149- for i , arg in enumerate (args ):
150- if i == skip_index :
151- continue
152- arg = arg .strip ()
153- if "=" in arg :
154- arg_name , val = arg .split ("=" )
155- if not string :
156- if "," in val :
157- val = val .split ("," )
158- val = [int (v , 0 ) for v in val ]
159- else :
160- val = int (val , 0 )
161- kwargs [arg_name ] = val
162- else :
163- arg_name , val = arg , args [i + 1 ]
164- try :
165- if not string :
166- if "," in val :
167- val = val .split ("," )
168- val = [int (v , 0 ) for v in val ]
169- else :
170- val = int (val , 0 )
171- kwargs [arg_name ] = val
172- skip_index = i + 1
173- except TypeError :
174- click .secho ("Error parsing arguments!" , fg = "yellow" )
175- execute = False
176- break
177- except ValueError :
178- click .secho ("Error parsing argument" , fg = "yellow" )
179- execute = False
180- break
181- return kwargs , execute
182-
183190 session = PromptSession (
184191 lexer = PygmentsLexer (PythonLexer ),
185192 completer = CmdCompleter (client ),
0 commit comments