package command;

import cli.CommandLineInterface;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.ParseException;

public class CommandSelector {

    private CommandLineInterface commandLineInterface;
    private String[] enteredCommand;

    public CommandSelector(String[] enteredCommand) {
        this.enteredCommand = enteredCommand;
        this.commandLineInterface = new CommandLineInterface();

    }

    public void executeCommand() {
        try {
            CommandLine userInput = commandLineInterface.getInput(enteredCommand);
            Command command;
            if (userInput.hasOption("create")) {
                command = createIssue();
            } else if (userInput.hasOption("push")) {
                command = pushIssue();
            } else {
                command = help();
            }
            command.execute();

        } catch (ParseException e) {
            e.printStackTrace();
        }
    }

    private Command help() {
        return new CommandHelp();
    }

    private Command createIssue() {
        return new CommandCreateIssue();
    }

    private Command pushIssue() {
        return new CommandPushIssue();
    }
}