@@ -1672,13 +1672,10 @@ def parseline(self, line: str) -> Tuple[str, str, str]:
1672
1672
statement = self .statement_parser .parse_command_only (line )
1673
1673
return statement .command , statement .args , statement .command_and_args
1674
1674
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 :
1677
1676
"""Top-level function called by cmdloop() to handle parsing a line and running the command and all of its hooks.
1678
1677
1679
1678
: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.
1682
1679
:param add_to_history: If True, then add this command to history. Defaults to True.
1683
1680
:param py_bridge_call: This should only ever be set to True by PyBridge to signify the beginning
1684
1681
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
1689
1686
1690
1687
stop = False
1691
1688
try :
1692
- statement = self ._input_line_to_statement (line , expand = expand )
1689
+ statement = self ._input_line_to_statement (line )
1693
1690
except EmptyStatement :
1694
1691
return self ._run_cmdfinalization_hooks (stop , None )
1695
1692
except ValueError as ex :
@@ -1804,15 +1801,12 @@ def _run_cmdfinalization_hooks(self, stop: bool, statement: Optional[Statement])
1804
1801
except Exception as ex :
1805
1802
self .pexcept (ex )
1806
1803
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 :
1809
1805
"""
1810
1806
Used when commands are being run in an automated fashion like text scripts or history replays.
1811
1807
The prompt and command line for each command will be printed if echo is True.
1812
1808
1813
1809
: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.
1816
1810
:param add_to_history: If True, then add these commands to history. Defaults to True.
1817
1811
:return: True if running of commands should stop
1818
1812
"""
@@ -1823,12 +1817,12 @@ def runcmds_plus_hooks(self, cmds: List[Union[HistoryItem, str]], *,
1823
1817
if self .echo :
1824
1818
self .poutput ('{}{}' .format (self .prompt , line ))
1825
1819
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 ):
1827
1821
return True
1828
1822
1829
1823
return False
1830
1824
1831
- def _complete_statement (self , line : str , * , expand : bool = True ) -> Statement :
1825
+ def _complete_statement (self , line : str ) -> Statement :
1832
1826
"""Keep accepting lines of input until the command is complete.
1833
1827
1834
1828
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:
1837
1831
backwards compatibility with the standard library version of cmd.
1838
1832
1839
1833
: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.
1842
1834
:return: the completed Statement
1843
1835
"""
1844
1836
while True :
1845
1837
try :
1846
- statement = self .statement_parser .parse (line , expand = expand )
1838
+ statement = self .statement_parser .parse (line )
1847
1839
if statement .multiline_command and statement .terminator :
1848
1840
# we have a completed multiline command, we are done
1849
1841
break
@@ -1854,7 +1846,7 @@ def _complete_statement(self, line: str, *, expand: bool = True) -> Statement:
1854
1846
except ValueError :
1855
1847
# we have unclosed quotation marks, lets parse only the command
1856
1848
# 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 )
1858
1850
if not statement .multiline_command :
1859
1851
# not a multiline command, so raise the exception
1860
1852
raise
@@ -1891,13 +1883,11 @@ def _complete_statement(self, line: str, *, expand: bool = True) -> Statement:
1891
1883
raise EmptyStatement ()
1892
1884
return statement
1893
1885
1894
- def _input_line_to_statement (self , line : str , * , expand : bool = True ) -> Statement :
1886
+ def _input_line_to_statement (self , line : str ) -> Statement :
1895
1887
"""
1896
1888
Parse the user's input line and convert it to a Statement, ensuring that all macros are also resolved
1897
1889
1898
1890
: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.
1901
1891
:return: parsed command line as a Statement
1902
1892
"""
1903
1893
used_macros = []
@@ -1906,14 +1896,14 @@ def _input_line_to_statement(self, line: str, *, expand: bool = True) -> Stateme
1906
1896
# Continue until all macros are resolved
1907
1897
while True :
1908
1898
# 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 )
1910
1900
1911
1901
# Save the fully entered line if this is the first loop iteration
1912
1902
if orig_line is None :
1913
1903
orig_line = statement .raw
1914
1904
1915
1905
# 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 :
1917
1907
used_macros .append (statement .command )
1918
1908
line = self ._resolve_macro (statement )
1919
1909
if line is None :
@@ -2127,22 +2117,19 @@ def _cmd_func_name(self, command: str) -> str:
2127
2117
return target if callable (getattr (self , target , None )) else ''
2128
2118
2129
2119
# 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 :
2132
2121
""" This executes the actual do_* method for a command.
2133
2122
2134
2123
If the command provided doesn't exist, then it executes default() instead.
2135
2124
2136
2125
:param statement: intended to be a Statement instance parsed command from the input stream, alternative
2137
2126
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.
2140
2127
:param add_to_history: If True, then add this command to history. Defaults to True.
2141
2128
:return: a flag indicating whether the interpretation of commands should stop
2142
2129
"""
2143
2130
# For backwards compatibility with cmd, allow a str to be passed in
2144
2131
if not isinstance (statement , Statement ):
2145
- statement = self ._input_line_to_statement (statement , expand = expand )
2132
+ statement = self ._input_line_to_statement (statement )
2146
2133
2147
2134
func = self .cmd_func (statement .command )
2148
2135
if func :
@@ -2331,6 +2318,10 @@ def _alias_create(self, args: argparse.Namespace) -> None:
2331
2318
self .perror ("Invalid alias name: {}" .format (errmsg ))
2332
2319
return
2333
2320
2321
+ if args .name in self .get_all_commands ():
2322
+ self .perror ("Alias cannot have the same name as a command" )
2323
+ return
2324
+
2334
2325
if args .name in self .macros :
2335
2326
self .perror ("Alias cannot have the same name as a macro" )
2336
2327
return
@@ -2460,8 +2451,8 @@ def _macro_create(self, args: argparse.Namespace) -> None:
2460
2451
self .perror ("Invalid macro name: {}" .format (errmsg ))
2461
2452
return
2462
2453
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" )
2465
2456
return
2466
2457
2467
2458
if args .name in self .aliases :
0 commit comments