예제 #1
0
def run_cmd2_app(app: cmd2.Cmd) -> None:
    """
    Run a cmd2 App as CLI or shell.
    Handle exit code return value, too.
    """
    if len(sys.argv) > 1:
        # CLI usage => run only one command and then exit
        app.onecmd_plus_hooks(line=argv2str(sys.argv[1:]))
        exit_code = app.exit_code
    else:
        exit_code = app.cmdloop()

    sys.exit(exit_code)
예제 #2
0
    def onecmd_plus_hooks(self, line, return_none=True):
        '''
        A single command called with the addtional options provided
        to configure the method call.
        Returned is the value from the Piped reduce call
        or the handler method.
        '''
        # print 'onecmd_plus_hooks', line
        self._lastcmd = line
        if PIPE in line:
            spl = line.split(PIPE)
            return self.run_commands_reduce(spl)
        else:
            v = Cmd.onecmd_plus_hooks(self, line)

            to_quit = False
            if v in (QUIT_EXIT, QUIT_NO_EXIT):
                to_quit = True
            if return_none is False or to_quit:
                return v
예제 #3
0
 def onecmd_plus_hooks(self, line):
     ''' Trigger hooks after command. '''
     if not line:
         return self.emptyline()
     return Cmd.onecmd_plus_hooks(self, line)
예제 #4
0
 def onecmd_plus_hooks(self, line):
     ''' Trigger hooks after command. '''
     if not line:
         return self.emptyline()
     return Cmd.onecmd_plus_hooks(self, line)