import os
from lk.classes.command import Command
from lk.utils.config_util import ConfigUtil
from lk.utils.shell_util import run_and_confirm


class Commands(object):

    def __init__(self):
        pass

    def get_empty_command(self, click_format):
        if click_format:
            command = self.get_click_command('empty-command')
        else:
            raise NotImplementedError
        return command

    def get_click_command(self, command_name):
        command = Command(command_name)
        with open(str(command.path)) as _file:
            args = {}
            code = compile(_file.read(), command.file_name, 'exec')
            eval(code, args, args)
        command = args['cli']
        return command

    def remove_command(self, command_name):
        command_path = Command(command_name).path
        run_and_confirm('rm {command_path}'.format(command_path=command_path))

    def get_commands(self):
        click_commands = {}
        commands_dirs = [ConfigUtil().user_commands_directory, ConfigUtil()
            .core_commands_directory]
        for command_dir in commands_dirs:
            for file_name in os.listdir(command_dir):
                if file_name.endswith('.py') and file_name != '__init__.py':
                    args = {}
                    file_path = os.path.join(command_dir, file_name)
                    with open(file_path) as _file:
                        code = compile(_file.read(), file_name, 'exec')
                        eval(code, args, args)
                    command = args['cli']
                    click_commands[command.name] = command
        lk_commands = {}
        for command_name, click_command in click_commands.iteritems():
            lk_command = Command(command_name)
            lk_commands[command_name] = lk_command
        return lk_commands

50bd655bcccae9e0e9645aed15171b023b898d4f
<mask token>


class Commands(object):

    def __init__(self):
        pass

    def get_empty_command(self, click_format):
        if click_format:
            command = self.get_click_command('empty-command')
        else:
            raise NotImplementedError
        return command
    <mask token>
    <mask token>

    def get_commands(self):
        click_commands = {}
        commands_dirs = [ConfigUtil().user_commands_directory, ConfigUtil()
            .core_commands_directory]
        for command_dir in commands_dirs:
            for file_name in os.listdir(command_dir):
                if file_name.endswith('.py') and file_name != '__init__.py':
                    args = {}
                    file_path = os.path.join(command_dir, file_name)
                    with open(file_path) as _file:
                        code = compile(_file.read(), file_name, 'exec')
                        eval(code, args, args)
                    command = args['cli']
                    click_commands[command.name] = command
        lk_commands = {}
        for command_name, click_command in click_commands.iteritems():
            lk_command = Command(command_name)
            lk_commands[command_name] = lk_command
        return lk_commands

<mask token>


class Commands(object):

    def __init__(self):
        pass

    def get_empty_command(self, click_format):
        if click_format:
            command = self.get_click_command('empty-command')
        else:
            raise NotImplementedError
        return command
    <mask token>

    def remove_command(self, command_name):
        command_path = Command(command_name).path
        run_and_confirm('rm {command_path}'.format(command_path=command_path))

    def get_commands(self):
        click_commands = {}
        commands_dirs = [ConfigUtil().user_commands_directory, ConfigUtil()
            .core_commands_directory]
        for command_dir in commands_dirs:
            for file_name in os.listdir(command_dir):
                if file_name.endswith('.py') and file_name != '__init__.py':
                    args = {}
                    file_path = os.path.join(command_dir, file_name)
                    with open(file_path) as _file:
                        code = compile(_file.read(), file_name, 'exec')
                        eval(code, args, args)
                    command = args['cli']
                    click_commands[command.name] = command
        lk_commands = {}
        for command_name, click_command in click_commands.iteritems():
            lk_command = Command(command_name)
            lk_commands[command_name] = lk_command
        return lk_commands

<mask token>


class Commands(object):

    def __init__(self):
        pass

    def get_empty_command(self, click_format):
        if click_format:
            command = self.get_click_command('empty-command')
        else:
            raise NotImplementedError
        return command

    def get_click_command(self, command_name):
        command = Command(command_name)
        with open(str(command.path)) as _file:
            args = {}
            code = compile(_file.read(), command.file_name, 'exec')
            eval(code, args, args)
        command = args['cli']
        return command

    def remove_command(self, command_name):
        command_path = Command(command_name).path
        run_and_confirm('rm {command_path}'.format(command_path=command_path))

    def get_commands(self):
        click_commands = {}
        commands_dirs = [ConfigUtil().user_commands_directory, ConfigUtil()
            .core_commands_directory]
        for command_dir in commands_dirs:
            for file_name in os.listdir(command_dir):
                if file_name.endswith('.py') and file_name != '__init__.py':
                    args = {}
                    file_path = os.path.join(command_dir, file_name)
                    with open(file_path) as _file:
                        code = compile(_file.read(), file_name, 'exec')
                        eval(code, args, args)
                    command = args['cli']
                    click_commands[command.name] = command
        lk_commands = {}
        for command_name, click_command in click_commands.iteritems():
            lk_command = Command(command_name)
            lk_commands[command_name] = lk_command
        return lk_commands

import os
from lk.classes.command import Command
from lk.utils.config_util import ConfigUtil
from lk.utils.shell_util import run_and_confirm


class Commands(object):

    def __init__(self):
        pass

    def get_empty_command(self, click_format):
        if click_format:
            command = self.get_click_command('empty-command')
        else:
            raise NotImplementedError
        return command

    def get_click_command(self, command_name):
        command = Command(command_name)
        with open(str(command.path)) as _file:
            args = {}
            code = compile(_file.read(), command.file_name, 'exec')
            eval(code, args, args)
        command = args['cli']
        return command

    def remove_command(self, command_name):
        command_path = Command(command_name).path
        run_and_confirm('rm {command_path}'.format(command_path=command_path))

    def get_commands(self):
        click_commands = {}
        commands_dirs = [ConfigUtil().user_commands_directory, ConfigUtil()
            .core_commands_directory]
        for command_dir in commands_dirs:
            for file_name in os.listdir(command_dir):
                if file_name.endswith('.py') and file_name != '__init__.py':
                    args = {}
                    file_path = os.path.join(command_dir, file_name)
                    with open(file_path) as _file:
                        code = compile(_file.read(), file_name, 'exec')
                        eval(code, args, args)
                    command = args['cli']
                    click_commands[command.name] = command
        lk_commands = {}
        for command_name, click_command in click_commands.iteritems():
            lk_command = Command(command_name)
            lk_commands[command_name] = lk_command
        return lk_commands
