|
@@ -67,47 +67,47 @@ class CommandInfo:
|
|
|
|
|
|
|
|
|
def add_param(self, paraminfo):
|
|
|
- """Add a ParamInfo object to this CommandInfo"""
|
|
|
+ """Add a ParamInfo object to this CommandInfo"""
|
|
|
self.params[paraminfo.name] = paraminfo
|
|
|
|
|
|
|
|
|
def has_param_with_name(self, param_name):
|
|
|
- """Returns true if the parameter with param_name exists"""
|
|
|
+ """Returns true if the parameter with param_name exists"""
|
|
|
return param_name in self.params
|
|
|
|
|
|
|
|
|
def get_param_with_name(self, param_name):
|
|
|
- """Returns the ParamInfo with the given name. Raises a
|
|
|
- KeyError if it doesn't exist"""
|
|
|
+ """Returns the ParamInfo with the given name. Raises a
|
|
|
+ KeyError if it doesn't exist"""
|
|
|
return self.params[param_name]
|
|
|
|
|
|
|
|
|
def get_params(self):
|
|
|
- """Returns a list of all ParamInfo objects for this CommandInfo"""
|
|
|
+ """Returns a list of all ParamInfo objects for this CommandInfo"""
|
|
|
return list(self.params.values())
|
|
|
|
|
|
|
|
|
def get_param_names(self):
|
|
|
- """Returns a list of the names of all parameters for this command"""
|
|
|
+ """Returns a list of the names of all parameters for this command"""
|
|
|
return list(self.params.keys())
|
|
|
|
|
|
|
|
|
def get_mandatory_param_names(self):
|
|
|
- """Returns a list of the names of all mandatory parameters for
|
|
|
- this command"""
|
|
|
+ """Returns a list of the names of all mandatory parameters for
|
|
|
+ this command"""
|
|
|
all_names = self.params.keys()
|
|
|
return [name for name in all_names
|
|
|
if not self.params[name].is_optional]
|
|
|
|
|
|
def get_param_name_by_position(self, pos, param_count):
|
|
|
- '''
|
|
|
+ """
|
|
|
Find a proper parameter name for the position 'pos':
|
|
|
If param_count is equal to the count of mandatory parameters of command,
|
|
|
and there is some optional parameter, find the first mandatory parameter
|
|
|
from the position 'pos' to the end. Else, return the name on position pos.
|
|
|
(This function will be changed if bindctl command line syntax is changed
|
|
|
in the future. )
|
|
|
- '''
|
|
|
+ """
|
|
|
if type(pos) != int:
|
|
|
raise KeyError(str(pos) + " is not an integer")
|
|
|
|
|
@@ -132,7 +132,7 @@ class CommandInfo:
|
|
|
|
|
|
|
|
|
def command_help(self):
|
|
|
- """Prints the help info for this command to stdout"""
|
|
|
+ """Prints the help info for this command to stdout"""
|
|
|
print("Command ", self)
|
|
|
print("\t\thelp (Get help for command)")
|
|
|
|
|
@@ -174,34 +174,34 @@ class ModuleInfo:
|
|
|
return str("%s \t%s" % (self.name, self.desc))
|
|
|
|
|
|
def add_command(self, command_info):
|
|
|
- """Add a CommandInfo to this ModuleInfo."""
|
|
|
+ """Add a CommandInfo to this ModuleInfo."""
|
|
|
self.commands[command_info.name] = command_info
|
|
|
|
|
|
def has_command_with_name(self, command_name):
|
|
|
- """Returns true if this module has a command with the given name."""
|
|
|
+ """Returns true if this module has a command with the given name."""
|
|
|
return command_name in self.commands
|
|
|
|
|
|
def get_command_with_name(self, command_name):
|
|
|
- """Returns the CommandInfo for the command with the given name.
|
|
|
- Raises a KeyError if not found"""
|
|
|
+ """Returns the CommandInfo for the command with the given name.
|
|
|
+ Raises a KeyError if not found"""
|
|
|
return self.commands[command_name]
|
|
|
|
|
|
def get_commands(self):
|
|
|
- """Returns a list of all CommandInfo objects for this module."""
|
|
|
+ """Returns a list of all CommandInfo objects for this module."""
|
|
|
return list(self.commands.values())
|
|
|
|
|
|
def get_command_names(self):
|
|
|
- """Returns a list of the names of all commands for this module."""
|
|
|
+ """Returns a list of the names of all commands for this module."""
|
|
|
return list(self.commands.keys())
|
|
|
|
|
|
def module_help(self):
|
|
|
- """Prints the help info for this module to stdout"""
|
|
|
+ """Prints the help info for this module to stdout"""
|
|
|
print("Module ", self, "\nAvailable commands:")
|
|
|
for k in self.commands.keys():
|
|
|
print("\t", self.commands[k])
|
|
|
|
|
|
def command_help(self, command):
|
|
|
- """Prints the help info for the command with the given name.
|
|
|
- Raises KeyError if not found"""
|
|
|
+ """Prints the help info for the command with the given name.
|
|
|
+ Raises KeyError if not found"""
|
|
|
self.commands[command].command_help()
|
|
|
|