(self, argv)
return args
Convert command-line arguments to dictionary.
Convert command-line arguments to dictionary.
Convert command - line arguments to dictionary .
def _get_arguments_dict(self, argv):
        """Convert command-line arguments to dictionary."""
        args = {}
        arg_deque = deque(argv)
        # positional arguments
        pos = 0
        # use -- to end option parsing, everything is a positional argument afterwards
        options_ended = False
        while arg_deque:
            arg = arg_deque.popleft()
            if not arg.startswith(u'-') or options_ended:
                # not an option flag, interpret as positional
                # strip enclosing quotes, but only if paired
                for quote in u'"\'':
                    if arg.startswith(quote) and arg.endswith(quote):
                        arg = arg.strip(quote)
                args[pos] = arg
                pos += 1
            elif arg == u'--':
                options_ended = True
            else:
                key, value = split_pair(arg, split_by=u'=', quote=u'"\'')
                # we know arg starts with -, not =, so key is not empty
                if key.startswith(u'--'):
                    # long option
                    if key[2:]:
                        self._append_arg(args, key[2:], value)
                else:
                    # starts with one dash
                    if not value:
                        # -key value, without = to connect
                        # only accept this for short options, long options with -- must have a =
                        # otherwise options with optional =True will absorb the option following
                        # only use the next value if it does not itself look like an option flag
                        if arg_deque:
                            if not arg_deque[0].startswith(u'-'):
                                value = arg_deque.popleft()
                    unused_value = self._append_short_args(args, key, value)
                    # if the value picked up is not used by the short option, push back as positional.
                    if unused_value:
                        arg_deque.appendleft(unused_value)
        return args
def _get_arguments_dict ( self , argv ) : args = { } arg_deque = deque ( argv ) # positional arguments pos = 0 # use -- to end option parsing, everything is a positional argument afterwards options_ended = False while arg_deque : arg = arg_deque . popleft ( ) if not arg . startswith ( u'-' ) or options_ended : # not an option flag, interpret as positional # strip enclosing quotes, but only if paired for quote in u'"\'' : if arg . startswith ( quote ) and arg . endswith ( quote ) : arg = arg . strip ( quote ) args [ pos ] = arg pos += 1 elif arg == u'--' : options_ended = True else : key , value = split_pair ( arg , split_by = u'=' , quote = u'"\'' ) # we know arg starts with -, not =, so key is not empty if key . startswith ( u'--' ) : # long option if key [ 2 : ] : self . _append_arg ( args , key [ 2 : ] , value ) else : # starts with one dash if not value : # -key value, without = to connect # only accept this for short options, long options with -- must have a = # otherwise options with optional =True will absorb the option following # only use the next value if it does not itself look like an option flag if arg_deque : if not arg_deque [ 0 ] . startswith ( u'-' ) : value = arg_deque . popleft ( ) unused_value = self . _append_short_args ( args , key , value ) # if the value picked up is not used by the short option, push back as positional. if unused_value : arg_deque . appendleft ( unused_value ) return args