def run(self): '''run the command and return result''' args = self.get_args() if isinstance(args, list): return Result.ok(self.process_list(args)) elif isinstance(args, dict): # if it's a dict and there are default arguments remove them if Command.DEFS in args: del args[Command.DEFS] return Result.ok(self.process_object(args)) else: return Result.ok(self.process_single(args))
def run(self): '''run the command and return result''' items = self.args.get(Command.DEFS, None) if items is None: items = json.load(sys.stdin) filter_names = self.args.get("type", None) if filter_names is None: return Result.bad_request("filter not specified") else: checks = [] for name in filter_names: if name not in util.TYPE_CHECKS: return Result.bad_request("filter not found: " + str(name)) else: filter_fun = util.TYPE_CHECKS[name] checks.append(self.modifier(filter_fun)) result = [] for item in items: if self.multichecker(check(item) for check in checks): result.append(item) return Result.ok(result)
def run(self): '''run the command and return result''' args = self.get_default_args() value = None if len(args) == 2: action, name = args elif len(args) == 3: action, name, value = args else: return Result.bad_request("expected 2 or 3 args") if action == "get": fail = self.args.get("fail", False) result = self.get(name, value, fail) elif action == "set": result = self.set(name, value) else: return Result.bad_request("expected valid action get or set") return Result.ok(result)