# -*- coding: utf-8 -*-

# Copyright (C) 2013-2014 Avencall
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>


from xivo.cli.commandline import CommandLine
from xivo.cli.exception import NoMatchingCommandError


class RawCommandLineParser(object):
    word_delimiter = ' '

    def __init__(self, command_registry):
        self.command_registry = command_registry

    def split(self, raw_command_line):
        return raw_command_line.split()

    def parse(self, raw_command_line):
        words = self.split(raw_command_line)
        try:
            command, command_args = self.command_registry.get_command_and_args(words)
        except NoMatchingCommandError:
            command = None
            command_args = None
        return CommandLine(words, command, command_args)
