@@ -1672,13 +1672,10 @@ def parseline(self, line: str) -> Tuple[str, str, str]:
16721672 statement = self .statement_parser .parse_command_only (line )
16731673 return statement .command , statement .args , statement .command_and_args
16741674
1675- def onecmd_plus_hooks (self , line : str , * , expand : bool = True , add_to_history : bool = True ,
1676- py_bridge_call : bool = False ) -> bool :
1675+ def onecmd_plus_hooks (self , line : str , * , add_to_history : bool = True , py_bridge_call : bool = False ) -> bool :
16771676 """Top-level function called by cmdloop() to handle parsing a line and running the command and all of its hooks.
16781677
16791678 :param line: command line to run
1680- :param expand: If True, then aliases, macros, and shortcuts will be expanded.
1681- Set this to False if the command token should not be altered. Defaults to True.
16821679 :param add_to_history: If True, then add this command to history. Defaults to True.
16831680 :param py_bridge_call: This should only ever be set to True by PyBridge to signify the beginning
16841681 of an app() call from Python. It is used to enable/disable the storage of the
@@ -1689,7 +1686,7 @@ def onecmd_plus_hooks(self, line: str, *, expand: bool = True, add_to_history: b
16891686
16901687 stop = False
16911688 try :
1692- statement = self ._input_line_to_statement (line , expand = expand )
1689+ statement = self ._input_line_to_statement (line )
16931690 except EmptyStatement :
16941691 return self ._run_cmdfinalization_hooks (stop , None )
16951692 except ValueError as ex :
@@ -1804,15 +1801,12 @@ def _run_cmdfinalization_hooks(self, stop: bool, statement: Optional[Statement])
18041801 except Exception as ex :
18051802 self .pexcept (ex )
18061803
1807- def runcmds_plus_hooks (self , cmds : List [Union [HistoryItem , str ]], * ,
1808- expand : bool = True , add_to_history : bool = True ) -> bool :
1804+ def runcmds_plus_hooks (self , cmds : List [Union [HistoryItem , str ]], * , add_to_history : bool = True ) -> bool :
18091805 """
18101806 Used when commands are being run in an automated fashion like text scripts or history replays.
18111807 The prompt and command line for each command will be printed if echo is True.
18121808
18131809 :param cmds: commands to run
1814- :param expand: If True, then aliases, macros, and shortcuts will be expanded.
1815- Set this to False if the command token should not be altered. Defaults to True.
18161810 :param add_to_history: If True, then add these commands to history. Defaults to True.
18171811 :return: True if running of commands should stop
18181812 """
@@ -1823,12 +1817,12 @@ def runcmds_plus_hooks(self, cmds: List[Union[HistoryItem, str]], *,
18231817 if self .echo :
18241818 self .poutput ('{}{}' .format (self .prompt , line ))
18251819
1826- if self .onecmd_plus_hooks (line , expand = expand , add_to_history = add_to_history ):
1820+ if self .onecmd_plus_hooks (line , add_to_history = add_to_history ):
18271821 return True
18281822
18291823 return False
18301824
1831- def _complete_statement (self , line : str , * , expand : bool = True ) -> Statement :
1825+ def _complete_statement (self , line : str ) -> Statement :
18321826 """Keep accepting lines of input until the command is complete.
18331827
18341828 There is some pretty hacky code here to handle some quirks of
@@ -1837,13 +1831,11 @@ def _complete_statement(self, line: str, *, expand: bool = True) -> Statement:
18371831 backwards compatibility with the standard library version of cmd.
18381832
18391833 :param line: the line being parsed
1840- :param expand: If True, then aliases and shortcuts will be expanded.
1841- Set this to False if the command token should not be altered. Defaults to True.
18421834 :return: the completed Statement
18431835 """
18441836 while True :
18451837 try :
1846- statement = self .statement_parser .parse (line , expand = expand )
1838+ statement = self .statement_parser .parse (line )
18471839 if statement .multiline_command and statement .terminator :
18481840 # we have a completed multiline command, we are done
18491841 break
@@ -1854,7 +1846,7 @@ def _complete_statement(self, line: str, *, expand: bool = True) -> Statement:
18541846 except ValueError :
18551847 # we have unclosed quotation marks, lets parse only the command
18561848 # and see if it's a multiline
1857- statement = self .statement_parser .parse_command_only (line , expand = expand )
1849+ statement = self .statement_parser .parse_command_only (line )
18581850 if not statement .multiline_command :
18591851 # not a multiline command, so raise the exception
18601852 raise
@@ -1891,13 +1883,11 @@ def _complete_statement(self, line: str, *, expand: bool = True) -> Statement:
18911883 raise EmptyStatement ()
18921884 return statement
18931885
1894- def _input_line_to_statement (self , line : str , * , expand : bool = True ) -> Statement :
1886+ def _input_line_to_statement (self , line : str ) -> Statement :
18951887 """
18961888 Parse the user's input line and convert it to a Statement, ensuring that all macros are also resolved
18971889
18981890 :param line: the line being parsed
1899- :param expand: If True, then aliases, macros, and shortcuts will be expanded.
1900- Set this to False if the command token should not be altered. Defaults to True.
19011891 :return: parsed command line as a Statement
19021892 """
19031893 used_macros = []
@@ -1906,14 +1896,14 @@ def _input_line_to_statement(self, line: str, *, expand: bool = True) -> Stateme
19061896 # Continue until all macros are resolved
19071897 while True :
19081898 # Make sure all input has been read and convert it to a Statement
1909- statement = self ._complete_statement (line , expand = expand )
1899+ statement = self ._complete_statement (line )
19101900
19111901 # Save the fully entered line if this is the first loop iteration
19121902 if orig_line is None :
19131903 orig_line = statement .raw
19141904
19151905 # Check if this command matches a macro and wasn't already processed to avoid an infinite loop
1916- if expand and statement .command in self .macros .keys () and statement .command not in used_macros :
1906+ if statement .command in self .macros .keys () and statement .command not in used_macros :
19171907 used_macros .append (statement .command )
19181908 line = self ._resolve_macro (statement )
19191909 if line is None :
@@ -2127,22 +2117,19 @@ def _cmd_func_name(self, command: str) -> str:
21272117 return target if callable (getattr (self , target , None )) else ''
21282118
21292119 # noinspection PyMethodOverriding
2130- def onecmd (self , statement : Union [Statement , str ], * ,
2131- expand : bool = True , add_to_history : bool = True ) -> bool :
2120+ def onecmd (self , statement : Union [Statement , str ], * , add_to_history : bool = True ) -> bool :
21322121 """ This executes the actual do_* method for a command.
21332122
21342123 If the command provided doesn't exist, then it executes default() instead.
21352124
21362125 :param statement: intended to be a Statement instance parsed command from the input stream, alternative
21372126 acceptance of a str is present only for backward compatibility with cmd
2138- :param expand: If True, then aliases, macros, and shortcuts will be expanded.
2139- Set this to False if the command token should not be altered. Defaults to True.
21402127 :param add_to_history: If True, then add this command to history. Defaults to True.
21412128 :return: a flag indicating whether the interpretation of commands should stop
21422129 """
21432130 # For backwards compatibility with cmd, allow a str to be passed in
21442131 if not isinstance (statement , Statement ):
2145- statement = self ._input_line_to_statement (statement , expand = expand )
2132+ statement = self ._input_line_to_statement (statement )
21462133
21472134 func = self .cmd_func (statement .command )
21482135 if func :
@@ -2331,6 +2318,10 @@ def _alias_create(self, args: argparse.Namespace) -> None:
23312318 self .perror ("Invalid alias name: {}" .format (errmsg ))
23322319 return
23332320
2321+ if args .name in self .get_all_commands ():
2322+ self .perror ("Alias cannot have the same name as a command" )
2323+ return
2324+
23342325 if args .name in self .macros :
23352326 self .perror ("Alias cannot have the same name as a macro" )
23362327 return
@@ -2460,8 +2451,8 @@ def _macro_create(self, args: argparse.Namespace) -> None:
24602451 self .perror ("Invalid macro name: {}" .format (errmsg ))
24612452 return
24622453
2463- if args .name in self .statement_parser . multiline_commands :
2464- self .perror ("Macro cannot have the same name as a multiline command" )
2454+ if args .name in self .get_all_commands () :
2455+ self .perror ("Macro cannot have the same name as a command" )
24652456 return
24662457
24672458 if args .name in self .aliases :
0 commit comments