Prevent overwriting built-in commands with aliases, as it would delete access to the built-in command permanently

master
Keegi 2011-06-01 20:49:12 +03:00
parent d2c1b08e31
commit cb2ddfbcbf
1 changed files with 3 additions and 0 deletions

View File

@ -99,6 +99,9 @@ class pronsole(cmd.Cmd):
print "Alias '"+alias_name+"' is not defined"
return
# (re)define an alias
if alias_name not in self.aliases.keys() and hasattr(self.__class__,"do_"+alias_name):
print "Name '"+alias_name+"' is already being used by built-in command"
return
func = lambda self,args,alias_def=alias_def: self.onecmd(" ".join((alias_def,args)))
self.aliases[alias_name] = alias_def
setattr(self.__class__,"do_"+alias_name,func)