Exemplo n.º 1
0
    def default(self, cmdline):
        try:
            if not cmdline:
                return self.emptyline()

            return self._execute_cmd(CommandInvocation.from_cmdline(cmdline))
        except Exception as e:
            self._last_exception = sys.exc_info()
            print(e)
        else:
            self._last_exception = None
Exemplo n.º 2
0
Arquivo: cmd.py Projeto: dextero/nsh
    def default(self, cmdline):
        try:
            if not cmdline:
                return self.emptyline()

            return self._execute_cmd(CommandInvocation.from_cmdline(cmdline))
        except Exception as e:
            self._last_exception = sys.exc_info()
            print(e)
        else:
            self._last_exception = None
Exemplo n.º 3
0
    def test_parse(self):
        assertEqual = self.assertEqual

        assertEqual(CommandInvocation(command=''),
                    CommandInvocation.from_cmdline(''))
        assertEqual(CommandInvocation(command='foo'),
                    CommandInvocation.from_cmdline('foo'))

        assertEqual(CommandInvocation(command='foo', free_args=['bar']),
                    CommandInvocation.from_cmdline('foo bar'))

        assertEqual(CommandInvocation(command='foo', free_args=['bar']),
                    CommandInvocation.from_cmdline('foo\tbar'))
        assertEqual(CommandInvocation(command='foo', free_args=['bar']),
                    CommandInvocation.from_cmdline('foo \tbar'))

        assertEqual(CommandInvocation(command='foo', free_args=['bar \tbaz']),
                    CommandInvocation.from_cmdline('foo "bar \tbaz"'))
        assertEqual(CommandInvocation(command='foo', free_args=['bar \tbaz']),
                    CommandInvocation.from_cmdline('foo \'bar \tbaz\''))

        assertEqual(CommandInvocation(command='foo', named_args={'bar': 'baz'}),
                    CommandInvocation.from_cmdline('foo bar=baz'))