def _set(self, args: Args) -> AnyErr: """ set - show or set a setting """ setting_to_set = args.get_positionals() log.d(f"setting_to_set: {setting_to_set}") if setting_to_set and len(setting_to_set) == 2: key, val = setting_to_set log.i(f"set {key}={val}") if key and val: try: set_setting(key, val) except Exception as ex: log.w(f"Failed to set: {ex}") return str(ex) else: log.w(f"Unable to parse setting: {setting_to_set}") return ClientErrors.INVALID_COMMAND_SYNTAX else: # Show aliases log.d("No setting given, showing current ones") for key, val in settings._settings_values.items(): print(f"set {key}={val}") return ClientErrors.SUCCESS
def _alias(self, args: Args) -> AnyErr: """ alias - show or create an alias """ alias_to_create = args.get_positionals() log.d(f"alias_to_create: {alias_to_create}") if alias_to_create and len(alias_to_create) == 2: # Create aliases source, target = alias_to_create if source and target: log.i(f"Adding alias: {source}={target}") self._aliases[source] = target comm_info = COMMANDS_INFO.get(self._command_for(source)) # If comm_info is None, the command is uknown or it is a multiple # command, add as a null comm_info self._available_commands[source] = comm_info else: log.w(f"Unable to parse alias: {alias_to_create}") return ClientErrors.INVALID_COMMAND_SYNTAX else: # Show aliases log.d("No alias given, showing current ones") for source, target in self._aliases.items(): print(f"alias {source}={target}") return ClientErrors.SUCCESS