src/orion/core/io/cmdline_parser.py
def parse(self, commandline):
        """Parse the `commandline` argument.

        This function will go through the list of strings and create a dictionary
        mapping every argument to its value(s). It will also form a template to recreate such a
        list. If `commandline` is empty or the `parse` function has already been called, it
        will return the dictionary of the already-parsed arguments.

        Parameters
        ----------
        commandline : list
            List of string representing the commmandline arguments.

        Returns
        -------
        dict
            Dictionary holding the values of every argument. The keys are the name of the arguments.

        Raises
        ------
        ValueError
            This exception is raised then the parser detects a duplicate argument.
        RuntimeError
            This exception is raised if the parser already parsed a commandline and contains a
            template.

        Notes
        -----
        Each argument is stored inside a `dict`.
        Inside that dictionary, the keys are created following these rules:

        -If the argument is a positional one, its key will be `'_pos_x'` where `x` is its index
        inside the list.
        -Otherwise, the key will be equal to the name of the argument minus the prefixed dashes.

        The values are stored in the following ways:

        -If the argument is a positional one, its value is simply its value inside the commandline.
        -If the argument is a named, boolean argument, its value is simply `True`.
        -If the argument is a named, single-valued argument, its value is stored as-is.
        -If the argument is a named, multi-valued argument, its value is a list containing each
        value following it until the next named argument.

        Positional arguments following a named argument are not currently supported.

        Examples
        --------
        Positional and named arguments:

        >>> parser = CmdlineParser()
        >>> parser.parse('python 1 --arg value'.split(' '))
        {'_pos_0': 'python', '_pos_1': '1', 'arg': 'value'}

        Named boolean argument:

        >>> parser.parse('python --boolean'.split(' '))
        {'_pos_0': 'python', 'boolean': True}

        Named multi-valued argument:

        >>> parser.parse('python --args value1 value2'.split(' '))
        {'_pos_0': 'python', 'args': ['value1', 'value2']}

        Named argument defined with `=`:

        >>> parser.parse('python --arg=value'.split(' '))
        {'_pos_0': 'python', 'arg': 'value'}

        """
        if self._already_parsed:
            raise RuntimeError("The commandline has already been parsed.")

        keys, arguments = self._parse_arguments(commandline)
        self.arguments = arguments
        self.keys = keys

        for key, value in arguments.items():
            # Handle positional arguments
            if key.startswith("_"):
                self.template.append("{" + key + "}")

            # Handle optional ones
            else:
                arg = self.keys[key]
                if arg in self.template:
                    continue

                self.template.append(arg)

                # Ignore value as key is a boolean argument
                if isinstance(value, bool):
                    continue

                if not isinstance(value, list):
                    template = "{" + key + "}"
                    self.template.append(template)
                    continue

                for pos in range(len(value)):
                    template = "{" + key + "[" + str(pos) + "]}"
                    self.template.append(template)

        self._already_parsed = True

        return self.arguments
Parse the `commandline` argument.

        This function will go through the list of strings and create a dictionary
        mapping every argument to its value(s). It will also form a template to recreate such a
        list. If `commandline` is empty or the `parse` function has already been called, it
        will return the dictionary of the already-parsed arguments.

        Parameters
        ----------
        commandline : list
            List of string representing the commmandline arguments.

        Returns
        -------
        dict
            Dictionary holding the values of every argument. The keys are the name of the arguments.

        Raises
        ------
        ValueError
            This exception is raised then the parser detects a duplicate argument.
        RuntimeError
            This exception is raised if the parser already parsed a commandline and contains a
            template.

        Notes
        -----
        Each argument is stored inside a `dict`.
        Inside that dictionary, the keys are created following these rules:

        -If the argument is a positional one, its key will be `'_pos_x'` where `x` is its index
        inside the list.
        -Otherwise, the key will be equal to the name of the argument minus the prefixed dashes.

        The values are stored in the following ways:

        -If the argument is a positional one, its value is simply its value inside the commandline.
        -If the argument is a named, boolean argument, its value is simply `True`.
        -If the argument is a named, single-valued argument, its value is stored as-is.
        -If the argument is a named, multi-valued argument, its value is a list containing each
        value following it until the next named argument.

        Positional arguments following a named argument are not currently supported.

        Examples
        --------
        Positional and named arguments:

        >>> parser = CmdlineParser()
        >>> parser.parse('python 1 --arg value'.split(' '))
        {'_pos_0': 'python', '_pos_1': '1', 'arg': 'value'}

        Named boolean argument:

        >>> parser.parse('python --boolean'.split(' '))
        {'_pos_0': 'python', 'boolean': True}

        Named multi-valued argument:

        >>> parser.parse('python --args value1 value2'.split(' '))
        {'_pos_0': 'python', 'args': ['value1', 'value2']}

        Named argument defined with `=`:

        >>> parser.parse('python --arg=value'.split(' '))
        {'_pos_0': 'python', 'arg': 'value'}

        
Parse the `commandline` argument.
This function will go through the list of strings and create a dictionary
mapping every argument to its value(s). It will also form a template to recreate such a
list. If `commandline` is empty or the `parse` function has already been called, it
will return the dictionary of the already-parsed arguments.

Parameters

commandline : list
List of string representing the commmandline arguments.

Returns

dict
Dictionary holding the values of every argument. The keys are the name of the arguments.

Raises

ValueError
This exception is raised then the parser detects a duplicate argument.
RuntimeError
This exception is raised if the parser already parsed a commandline and contains a
template.

Notes

Each argument is stored inside a `dict`.
Inside that dictionary, the keys are created following these rules.

If the argument is a positional one, its key will be `'_pos_x'` where `x` is its index
inside the list.
Otherwise, the key will be equal to the name of the argument minus the prefixed dashes.

The values are stored in the following ways.

If the argument is a positional one, its value is simply its value inside the commandline.
If the argument is a named, boolean argument, its value is simply `True`.
If the argument is a named, single-valued argument, its value is stored as-is.
If the argument is a named, multi-valued argument, its value is a list containing each
value following it until the next named argument.

Positional arguments following a named argument are not currently supported.

Examples

Positional and named arguments.



Named boolean argument.



Named multi-valued argument.



Named argument defined with `=`.


Parse the ` commandline ` argument . This function will go through the list of strings and create a dictionary mapping every argument to its value ( s ) . It will also form a template to recreate such a list . If ` commandline ` is empty or the ` parse ` function has already been called it will return the dictionary of the already - parsed arguments . Parameters commandline : list List of string representing the commmandline arguments . Returns dict Dictionary holding the values of every argument . The keys are the name of the arguments . Raises ValueError This exception is raised then the parser detects a duplicate argument . RuntimeError This exception is raised if the parser already parsed a commandline and contains a template . Notes Each argument is stored inside a ` dict ` . Inside that dictionary the keys are created following these rules . If the argument is a positional one its key will be ` ' _pos_x ' ` where ` x ` is its index inside the list . Otherwise the key will be equal to the name of the argument minus the prefixed dashes . The values are stored in the following ways . If the argument is a positional one its value is simply its value inside the commandline . If the argument is a named boolean argument its value is simply ` True ` . If the argument is a named single - valued argument its value is stored as - is . If the argument is a named multi - valued argument its value is a list containing each value following it until the next named argument . Positional arguments following a named argument are not currently supported . Examples Positional and named arguments . Named boolean argument . Named multi - valued argument . Named argument defined with ` = ` .
def parse(self, commandline):
        if self._already_parsed:
            raise RuntimeError("The commandline has already been parsed.")
        keys, arguments = self._parse_arguments(commandline)
        self.arguments = arguments
        self.keys = keys
        for key, value in arguments.items():
            if key.startswith("_"):
                self.template.append("{" + key + "}")
            else:
                arg = self.keys[key]
                if arg in self.template:
                    continue
                self.template.append(arg)
                if isinstance(value, bool):
                    continue
                if not isinstance(value, list):
                    template = "{" + key + "}"
                    self.template.append(template)
                    continue
                for pos in range(len(value)):
                    template = "{" + key + "[" + str(pos) + "]}"
                    self.template.append(template)
        self._already_parsed = True
        return self.arguments
def parse ( self , commandline ) : if self . _already_parsed : raise RuntimeError ( "The commandline has already been parsed." ) keys , arguments = self . _parse_arguments ( commandline ) self . arguments = arguments self . keys = keys for key , value in arguments . items ( ) : if key . startswith ( "_" ) : self . template . append ( "{" + key + "}" ) else : arg = self . keys [ key ] if arg in self . template : continue self . template . append ( arg ) if isinstance ( value , bool ) : continue if not isinstance ( value , list ) : template = "{" + key + "}" self . template . append ( template ) continue for pos in range ( len ( value ) ) : template = "{" + key + "[" + str ( pos ) + "]}" self . template . append ( template ) self . _already_parsed = True return self . arguments
Parse the `commandline` argument.
Parse the ` commandline ` argument .
"""Parse the `commandline` argument.

        This function will go through the list of strings and create a dictionary
        mapping every argument to its value(s). It will also form a template to recreate such a
        list. If `commandline` is empty or the `parse` function has already been called, it
        will return the dictionary of the already-parsed arguments.

        Parameters
        ----------
        commandline : list
            List of string representing the commmandline arguments.

        Returns
        -------
        dict
            Dictionary holding the values of every argument. The keys are the name of the arguments.

        Raises
        ------
        ValueError
            This exception is raised then the parser detects a duplicate argument.
        RuntimeError
            This exception is raised if the parser already parsed a commandline and contains a
            template.

        Notes
        -----
        Each argument is stored inside a `dict`.
        Inside that dictionary, the keys are created following these rules:

        -If the argument is a positional one, its key will be `'_pos_x'` where `x` is its index
        inside the list.
        -Otherwise, the key will be equal to the name of the argument minus the prefixed dashes.

        The values are stored in the following ways:

        -If the argument is a positional one, its value is simply its value inside the commandline.
        -If the argument is a named, boolean argument, its value is simply `True`.
        -If the argument is a named, single-valued argument, its value is stored as-is.
        -If the argument is a named, multi-valued argument, its value is a list containing each
        value following it until the next named argument.

        Positional arguments following a named argument are not currently supported.

        Examples
        --------
        Positional and named arguments:

        >>> parser = CmdlineParser()
        >>> parser.parse('python 1 --arg value'.split(' '))
        {'_pos_0': 'python', '_pos_1': '1', 'arg': 'value'}

        Named boolean argument:

        >>> parser.parse('python --boolean'.split(' '))
        {'_pos_0': 'python', 'boolean': True}

        Named multi-valued argument:

        >>> parser.parse('python --args value1 value2'.split(' '))
        {'_pos_0': 'python', 'args': ['value1', 'value2']}

        Named argument defined with `=`:

        >>> parser.parse('python --arg=value'.split(' '))
        {'_pos_0': 'python', 'arg': 'value'}

        """ # Handle positional arguments # Handle optional ones # Ignore value as key is a boolean argument
self
commandline