def parse(self, arguments, check_file_exist=True):
        # if you only want to parse a string and not checking for file existence, change flag check_file_exist
        self.check_file_exist = check_file_exist

        # if no arguments, print usage and quit
        if len(arguments) == 0 and len([opt for opt in self.options if self.options[opt].mandatory]) != 0:
            self.usage.error()

        # check if help is asked by the user
        if "-h" in arguments:
            print(self.usage.generate())
            exit(1)

        if "-sf" in arguments:
            doc_sourceforge = DocSourceForge(self, self.file_name)
            doc_sourceforge.generate()
            exit(1)

        # initialize results
        dictionary = dict()

        # initialize the spelling checker
        self.spelling.setWordsAsList([name for name in self.options])

        # checking if some file names or folder names contains spaces.
        # We suppose here that the user provides correct structure of arguments (i.e., one "-something", one "argument value", one "-somethingelse", one "another argument value", etc.)
        # We also suppose that multiple spaces can be present
        # we also check if double-quotes are present. If so, we need to concatenate the fields.
        arguments_temp = []
        index_next = 0
        for index in range(0,len(arguments)):
            if index == index_next:
                if arguments[index][0] == '-':
                    arguments_temp.append(arguments[index])
                    index_next = index+1
                else:
                    temp_str = arguments[index]
                    index_temp = index
                    if index_temp < len(arguments)-1:
                        if arguments[index][0] == '"':
                            while arguments[index_temp + 1][-1] != '"':  # loop until we find a double quote. Then concatenate.
                                temp_str += ' ' + arguments[index_temp + 1]
                                index_temp += 1
                                if index_temp >= len(arguments) - 1:
                                    break
                            temp_str += ' ' + arguments[index_temp + 1]
                            temp_str = temp_str[1:-1]
                        else:
                            while arguments[index_temp+1][0] != '-':  # check if a space is present. If so, concatenation of strings.
                                temp_str += ' '+arguments[index_temp+1]
                                index_temp += 1
                                if index_temp >= len(arguments)-1:
                                    break
                    index_next = index_temp+1
                    if '"' not in temp_str:
                        arguments_temp.append(temp_str)
        arguments = arguments_temp

        skip = False
        for index, arg in enumerate(arguments):
            if skip:  # if argument need to be skipped, we pass
                skip = False
                continue

            if arg in self.options:
                if self.options[arg].deprecated_rm:
                    sct.printv("ERROR : "+arg+" is a deprecated argument and is no longer supported by the current version.", 1, 'error')
                # for each argument, check if is in the option list.
                # if so, check the integrity of the argument
                if self.options[arg].deprecated:
                    sct.printv("WARNING : "+arg+" is a deprecated argument and will no longer be updated in future versions.", 1, 'warning')
                if self.options[arg].deprecated_by is not None:
                    try:
                        sct.printv("WARNING : "+arg+" is a deprecated argument and will no longer be updated in future versions. Changing argument to "+self.options[arg].deprecated_by+".", 1, 'warning')
                        arg = self.options[arg].deprecated_by
                    except KeyError as e:
                        sct.printv("ERROR : Current argument non existent : " + e.message, 1, 'error')
                if self.options[arg].type_value:
                    if len(arguments) > index+1:  # Check if option is not the last item
                        param = arguments[index+1]
                    else:
                        self.usage.error("ERROR: Option " + self.options[arg].name + " needs an argument...")

                    # check if option has an argument that is not another option
                    if param in self.options:
                        self.usage.error("ERROR: Option " + self.options[arg].name + " needs an argument...")

                    dictionary[arg] = self.options[arg].check_integrity(param)
                    skip = True
                else:
                    dictionary[arg] = True
            else:
                # if not in the list of known options, there is a syntax error in the list of arguments
                # check if the input argument is close to a known option
                spelling_candidates = self.spelling.correct(arg)
                if len(spelling_candidates) != 0:
                    self.usage.error("ERROR: argument "+arg+" does not exist. Did you mean: "+', '.join(spelling_candidates) + '?')
                else:
                    self.usage.error("ERROR: argument "+arg+" does not exist. See documentation.")

        # check if all mandatory arguments are provided by the user
        for option in [opt for opt in self.options if self.options[opt].mandatory and self.options[opt].deprecated_by is None]:
            if option not in dictionary:
                self.usage.error('ERROR: ' + option + ' is a mandatory argument.\n')

        # check if optional arguments with default values are all in the dictionary. If not, add them.
        for option in [opt for opt in self.options if not self.options[opt].mandatory]:
            if option not in dictionary and self.options[option].default_value:
                dictionary[option] = self.options[option].default_value

        # return a dictionary with each option name as a key and the input as the value
        return dictionary
dataset/ETHPy150Open neuropoly/spinalcordtoolbox/scripts/msct_parser.py/Parser.parse/original