All Downloads are FREE. Search and download functionalities are using the official Maven repository.

smolok.cmd.BaseCommand.groovy Maven / Gradle / Ivy

There is a newer version: 0.0.11
Show newest version
package smolok.cmd

abstract class BaseCommand implements Command {

    private final String[] commandPrefix

    BaseCommand(String[] commandPrefix) {
        this.commandPrefix = commandPrefix
    }

    @Override
    boolean supports(String... command) {
        if(commandPrefix.length > command.length) {
            return false
        }

        for(int i = 0; i < commandPrefix.length; i++) {
            if(commandPrefix[i] != command[i]) {
                return false
            }
        }

        true
    }

    protected String option(String[] command, String optionName, String defaultValue) {
        def optionFound = command.find{ it.startsWith("--${optionName}=") }
        optionFound != null ? optionFound.replaceFirst(/--${optionName}=/, '') : defaultValue
    }

    protected Optional option(String[] command, String optionName) {
        Optional.ofNullable(option(command, optionName, null))
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy