Example #1
0
    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
Example #2
0
    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
Example #3
0
    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)
Example #4
0
    def powercmd_parse(text):
        from powercmd.utils import match_instance

        try:
            return Option.ACCEPT(int(text))
        except ValueError:
            return match_instance(AcceptOption, text)
Example #5
0
    def powercmd_parse(text):
        from powercmd.utils import match_instance

        try:
            return Option.CONTENT_FORMAT(int(text))
        except ValueError:
            return match_instance(ContentFormatOption, text)
Example #6
0
    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)
Example #7
0
    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)
Example #8
0
    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)
Example #9
0
    def powercmd_parse(text):
        from powercmd.utils import match_instance

        return match_instance(Type, text)
Example #10
0
 def powercmd_parse(text):
     try:
         return Option.CONTENT_FORMAT(int(text))
     except ValueError:
         return match_instance(ContentFormatOption, text)