def powercmd_parse(text): from powercmd.utils import match_instance paren_idx = text.find('(') if paren_idx >= 0: ctor = match_instance(Option, text[:paren_idx], match_extra_cls=[OptionConstructor]) arg = eval(text[paren_idx:]) opt = ctor(*arg) if isinstance(arg, tuple) else ctor(arg) else: opt = match_instance(Option, text) return opt
def powercmd_parse(text): from powercmd.utils import match_instance, get_available_instance_names paren_idx = text.find('(') if paren_idx >= 0: ctor = match_instance(Option, text[:paren_idx], match_extra_cls=[OptionConstructor]) arg = eval(text[paren_idx:]) opt = ctor(*arg) if isinstance(arg, tuple) else ctor(arg) else: opt = match_instance(Option, text) return opt
def powercmd_complete(text): from powercmd.utils import match_instance, get_available_instance_names from powercmd.match_string import match_string paren_idx = text.find('(') if paren_idx >= 0: # argument completion opt_name = text[:paren_idx] if opt_name == 'Option': ctor = Option else: ctor = match_instance(Option, text[:paren_idx], match_extra_cls=[OptionConstructor]) if not ctor: return [] elif isinstance(ctor, OptionConstructor): ctor = ctor.content_mapper sig = inspect.signature(ctor) # the '' is a hack to prevent Cmd from actually inserting the completion return ['', str(sig)] possible = get_available_instance_names(Option, match_extra_cls=[OptionConstructor], append_paren_to_callables=True) return match_string(text, possible)
def powercmd_parse(text): from powercmd.utils import match_instance try: return Option.ACCEPT(int(text)) except ValueError: return match_instance(AcceptOption, text)
def powercmd_parse(text): from powercmd.utils import match_instance try: return Option.CONTENT_FORMAT(int(text)) except ValueError: return match_instance(ContentFormatOption, text)
def powercmd_complete(text): from powercmd.utils import match_instance, get_available_instance_names from powercmd.match_string import match_string paren_idx = text.find('(') if paren_idx >= 0: # argument completion opt_name = text[:paren_idx] if opt_name == 'Option': ctor = Option else: ctor = match_instance(Option, text[:paren_idx], match_extra_cls=[OptionConstructor]) if not ctor: return [] if isinstance(ctor, OptionConstructor): ctor = ctor.content_mapper sig = inspect.signature(ctor) # the '' is a hack to prevent Cmd from actually inserting the completion return ['', str(sig)] possible = get_available_instance_names(Option, match_extra_cls=[OptionConstructor], append_paren_to_callables=True) return match_string(text, possible)
def powercmd_parse(text): from powercmd.utils import match_instance try: cls, detail = map(int, text.split('.')) return Code(cls, detail) except ValueError: return match_instance(Code, text)
def powercmd_parse(text): from powercmd.utils import match_instance return match_instance(Type, text)
def powercmd_parse(text): try: return Option.CONTENT_FORMAT(int(text)) except ValueError: return match_instance(ContentFormatOption, text)