@@ -1998,25 +1998,16 @@ def onecmd(self, statement: Union[Statement, str]) -> bool:
19981998 if statement .command in self .macros :
19991999 stop = self ._run_macro (statement )
20002000 else :
2001- command = statement .command
2002- func = self .cmd_func (command )
2003- func_arg = statement .args
2004-
2005- if not func and self .default_to_shell :
2006- command = 'shell'
2007- func = self .cmd_func (command )
2008- func_arg = statement .command_and_args
2009-
2001+ func = self .cmd_func (statement .command )
20102002 if func :
2011- # Check if this command should be stored in the history
2012- if command not in self .exclude_from_history :
2003+ # Since we have a valid command store it in the history
2004+ if statement . command not in self .exclude_from_history :
20132005 self .history .append (statement .raw )
20142006
2015- stop = func (func_arg )
2007+ stop = func (statement )
20162008
20172009 else :
2018- self .default (statement )
2019- stop = False
2010+ stop = self .default (statement )
20202011
20212012 if stop is None :
20222013 stop = False
@@ -2067,12 +2058,18 @@ def _run_macro(self, statement: Statement) -> bool:
20672058 # Run the resolved command
20682059 return self .onecmd_plus_hooks (resolved )
20692060
2070- def default (self , statement : Statement ) -> None :
2071- """Called on an input line when the command prefix is not recognized .
2061+ def default (self , statement : Statement ) -> Optional [ bool ] :
2062+ """Executed when the command given isn't a recognized command implemented by a do_* method .
20722063
20732064 :param statement: Statement object with parsed input
20742065 """
2075- self .poutput ('*** {} is not a recognized command, alias, or macro\n ' .format (statement .command ))
2066+ if self .default_to_shell :
2067+ if 'shell' not in self .exclude_from_history :
2068+ self .history .append (statement .raw )
2069+
2070+ return self .do_shell (statement .command_and_args )
2071+ else :
2072+ self .poutput ('*** {} is not a recognized command, alias, or macro\n ' .format (statement .command ))
20762073
20772074 def pseudo_raw_input (self , prompt : str ) -> str :
20782075 """Began life as a copy of cmd's cmdloop; like raw_input but
0 commit comments