@@ -121,6 +121,53 @@ def convert(self, value, param, ctx):
121121 return None
122122
123123
124+ def _process_args (args , 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+ for i , arg in enumerate (args ):
137+ if i == skip_index :
138+ continue
139+ arg = arg .strip ()
140+ if "=" in arg :
141+ arg_name , val = arg .split ("=" )
142+ if not string :
143+ if "," in val :
144+ val = val .split ("," )
145+ val = [int (v , 0 ) for v in val ]
146+ else :
147+ val = int (val , 0 )
148+ kwargs [arg_name ] = val
149+ else :
150+ arg_name , val = arg , args [i + 1 ]
151+ try :
152+ if not string :
153+ if "," in val :
154+ val = val .split ("," )
155+ val = [int (v , 0 ) for v in val ]
156+ else :
157+ val = int (val , 0 )
158+ kwargs [arg_name ] = val
159+ skip_index = i + 1
160+ except TypeError :
161+ click .secho ("Error parsing arguments!" , fg = "yellow" )
162+ execute = False
163+ break
164+ except ValueError :
165+ click .secho ("Error parsing argument" , fg = "yellow" )
166+ execute = False
167+ break
168+ return kwargs , execute
169+
170+
124171def cli (client ): # noqa: C901 pylint: disable=too-complex
125172 """Run client definition."""
126173 use_keys = KeyBindings ()
@@ -142,44 +189,6 @@ def _(event):
142189 buffer = event .cli .current_buffer
143190 buffer .complete_state = None
144191
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-
183192 session = PromptSession (
184193 lexer = PygmentsLexer (PythonLexer ),
185194 completer = CmdCompleter (client ),
0 commit comments