示例#1
0
def main():
    cwd = os.path.abspath(os.path.curdir)
    filepath = os.path.join(cwd, '.env')
    if not os.path.isfile(filepath):
        sys.stderr.write('ERROR: This directory does not contain a .env file '
                         'or the .env file is a directory.\n')
        sys.exit(1)

    # reads sys.argv
    args = Arguments()
    config = Config(filepath)
    handle_command_path(config)
    command_section = config['commands']
    for command_name in command_section.sections:
        if command_name != 'DEFAULT':
            section=command_section[command_name]
            make_custom_command(section=section,
                                cmd_name=command_name,
                                cmd_aliases=section['aliases'])
    command_cls = Command.lookup_command(args.command)
    command = command_cls()
    # hack - We need config to get the command, but we also need command
    # to get args.  Thus, we attach the args attribute after instantiation
    config.args = command.parse_args(args.arguments)
    command.main(config.args, config)
示例#2
0
 def parse_args(self, raw_args):
     if len(raw_args) >= 1:
         secondary_command_name = raw_args[0]
         secondary_command_cls = Command.lookup_command(secondary_command_name)
         secondary_command = secondary_command_cls()
         secondary_command.print_help()
     else:
         self.print_main_help()
     sys.exit(0)
示例#3
0
def test_lookup_from_toplevel():
    class MyCommand(Command):
        pass

    sys.modules["my_command"] = MyCommand
    try:
        command = Command.lookup_command("my_command")
        assert command is MyCommand
    finally:
        del sys.modules["my_command"]
示例#4
0
def test_import_dot_qualified():
    # Using MyCommand2 just in case something didn't get cleaned up in
    # previous tests.
    class MyCommand2(Command):
        pass

    envbuilder.my_command2 = MyCommand2
    try:
        command = Command.lookup_command("envbuilder.my_command2")
        assert command is MyCommand2
    finally:
        del envbuilder.my_command2
示例#5
0
def test_lookup_builtin():
    class SomeCommand(BuiltinCommand):
        name = "some_command"

    command = Command.lookup_command("some_command")
    assert command is SomeCommand