diff --git a/src/bin/bigtool/run_bigtool.py b/src/bin/bigtool/run_bigtool.py index c362856b64..f267cc0510 100644 --- a/src/bin/bigtool/run_bigtool.py +++ b/src/bin/bigtool/run_bigtool.py @@ -59,7 +59,7 @@ def prepare_config_commands(bigtool): cmd = CommandInfo(name = "add", desc = "Add entry to configuration list", need_inst_param = False) param = ParamInfo(name = "identifier", type = "string", optional=True) cmd.add_param(param) - param = ParamInfo(name = "value", type = "string", optional=True) + param = ParamInfo(name = "value", type = "string", optional=False) cmd.add_param(param) module.add_command(cmd) @@ -88,6 +88,11 @@ def prepare_config_commands(bigtool): cmd = CommandInfo(name = "commit", desc = "Commit all local changes", need_inst_param = False) module.add_command(cmd) + cmd = CommandInfo(name = "go", desc = "Go to a specific configuration part", need_inst_param = False) + param = ParamInfo(name = "identifier", type="string", optional=False) + cmd.add_param(param) + module.add_command(cmd) + bigtool.add_module_info(module) diff --git a/src/lib/bigtool/bigtool.py b/src/lib/bigtool/bigtool.py index fbedcd5bdf..26d8d4f70d 100644 --- a/src/lib/bigtool/bigtool.py +++ b/src/lib/bigtool/bigtool.py @@ -30,13 +30,19 @@ class BigTool(Cmd): def __init__(self, session = None): Cmd.__init__(self) - self.prompt = '> ' + self.location = "" + self.prompt_end = '> ' + self.prompt = self.prompt_end self.ruler = '-' self.modules = OrderedDict() self.add_module_info(ModuleInfo("help", desc = "Get help for bigtool")) self.cc = session self.config_data = ISC.CC.data.UIConfigData("", session) + def postcmd(self, stop, line): + self.prompt = self.location + self.prompt_end + return stop + def validate_cmd(self, cmd): if not cmd.module in self.modules: raise CmdUnknownModuleSyntaxError(cmd.module) @@ -124,7 +130,7 @@ class BigTool(Cmd): def onecmd(self, line): - if line == 'EOF'or line.lower() == "quit": + if line == 'EOF' or line.lower() == "quit": return True if line == 'h': @@ -146,7 +152,7 @@ class BigTool(Cmd): text) if cmd.module == "config": # grm text has been stripped of slashes... - my_text = cur_line.rpartition(" ")[2] + my_text = self.location + "/" + cur_line.rpartition(" ")[2] list = self.config_data.config.get_item_list(my_text.rpartition("/")[0]) hints.extend([val for val in list if val.startswith(text)]) except CmdModuleNameFormatError: @@ -249,10 +255,15 @@ class BigTool(Cmd): def apply_config_cmd(self, cmd): - identifier = "" + identifier = self.location try: if 'identifier' in cmd.params: - identifier = cmd.params['identifier'] + if not identifier.endswith("/"): + identifier += "/" + if cmd.params['identifier'].startswith("/"): + identifier = cmd.params['identifier'] + else: + identifier += cmd.params['identifier'] if cmd.command == "show": values = self.config_data.get_value_maps(identifier) for value_map in values: @@ -280,10 +291,25 @@ class BigTool(Cmd): self.config_data.revert() elif cmd.command == "commit": self.config_data.commit(self.cc) + elif cmd.command == "go": + self.go(identifier) except ISC.CC.data.DataTypeError as dte: print("Error: " + str(dte)) except ISC.CC.data.DataNotFoundError as dnfe: print("Error: " + identifier + " not found") + except KeyError as ke: + print("Error: missing " + str(ke)) + + def go(self, identifier): + # just to see if it exists + self.config_data.get_value(identifier) + # some sanitizing + identifier = identifier.replace("//", "/") + if not identifier.startswith("/"): + identifier = "/" + identifier + if identifier.endswith("/"): + identifier = identifier[:-1] + self.location = identifier def apply_cmd(self, cmd): if not self.cc: