Exemple #1
0
    def _dec(f):
        klass_name = "%sCommand" % to_camel_case(f.__name__)

        class _CmdFakeMetaclass(type):
            def __init__(cls, name, bases, d):
                super(_CmdFakeMetaclass, cls).__init__(name, bases, d)
                name = cls.__name__

        klass = _CmdFakeMetaclass(klass_name, (Command,), {})

        if f.__name__.startswith("_"):
            COMMANDS_REGISTRY.register_command(f.__name__, klass, public=False)
        else:
            COMMANDS_REGISTRY.register_command(f.__name__, klass)
        if bypass_help:
            def run(self, ctx):
                o, a = ctx.options_context.parser.parse_args(ctx.get_command_arguments())
                if o.help:
                    ctx.options_context.parser.print_help()
                    return
                return f(ctx)
        else:
            run = lambda self, ctx: f(ctx)
        klass.run = run
        if f.__doc__:
            klass.long_descr = f.__doc__
        return f
Exemple #2
0
 def test_to_camel_case(self):
     d = [("foo", "Foo"), ("foo_bar", "FooBar"), ("_foo_bar", "_FooBar"), ("__fubar", "__Fubar"),
          ("_fubar_", "_Fubar_")]
     for lower, camel in d:
         self.assertEqual(to_camel_case(lower), camel)