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

com.yammer.dropwizard.cli.Command Maven / Gradle / Ivy

package com.yammer.dropwizard.cli;

import com.yammer.dropwizard.AbstractService;
import com.yammer.dropwizard.util.JarLocation;
import org.apache.commons.cli.*;

import java.util.Collection;

import static com.google.common.base.Preconditions.checkNotNull;
import static java.lang.String.format;

/**
 * A basic CLI command.
 */
public abstract class Command {
    private final String name;
    private final String description;

    /**
     * Create a new {@link Command} instance.
     *
     * @param name the command name (must be unique for the service)
     * @param description the description of the command
     */
    protected Command(String name,
                      String description) {
        this.name = checkNotNull(name);
        this.description = checkNotNull(description);
    }

    /**
     * Returns the command's name.
     *
     * @return the command's name
     */
    public final String getName() {
        return name;
    }

    /**
     * Returns the command's description.
     *
     * @return the command's description
     */
    public final String getDescription() {
        return description;
    }

    /**
     * Returns an empty {@link Options} instance. Override this to allow your commands to parse
     * command line arguments.
     *
     * @return an empty {@link Options} instance
     */
    public Options getOptions() {
        return new Options();
    }

    @SuppressWarnings("unchecked")
    final Options getOptionsWithHelp() {
        final Options options = new Options();
        for (Option option : (Collection




© 2015 - 2024 Weber Informatics LLC | Privacy Policy