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

org.duracloud.common.cli.CommandExecutor Maven / Gradle / Ivy

There is a newer version: 8.1.0
Show newest version
/*
 * The contents of this file are subject to the license and copyright
 * detailed in the LICENSE and NOTICE files at the root of the source
 * tree and available online at
 *
 *     http://duracloud.org/license/
 */
package org.duracloud.common.cli;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Daniel Bernstein
 */
public class CommandExecutor {
    private Map commandMap = new HashMap<>();
    private Command help = new GenericHelpCommand(commandMap);

    public CommandExecutor() {
        add(help);
    }

    public void add(Command command) {
        this.commandMap.put(command.getCommandName(), command);
    }

    public void execute(String[] args) {
        Command command = null;
        if (args.length == 0 || (command = commandMap.get(args[0])) == null) {
            help.execute(args);
        } else {
            command.execute(args);
        }
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy