commands.Command.java Source code

Java tutorial

Introduction

Here is the source code for commands.Command.java

Source

/**
 * This file is a component of jiminix
 *
 * Copyright (c) 2013 Jason Campos <jcampos8782@gmail.com>
 * All Rights Reserved.
 *
 * This software is licensed under The MIT License (MIT)
 * http://opensource.org/licenses/MIT
 */
package commands;

import java.io.File;
import java.util.Collection;
import java.util.concurrent.Callable;

import org.apache.commons.cli.Options;

import exceptions.UsageException;

/**
 * An interface for any command which is to be interpreted by a {@link shells.Shell Shell}. 
 * 
 * @author Jason Campos <jcampos8782@gmail.com>
 */
public interface Command extends Callable<Void> {
    /**
     * Throws a usage exception which describes the proper usage of the command
     * @throws UsageException The usage exception which describes the proper usage of the command
     */
    void usage() throws UsageException;

    /**
     * Retrieves available Options for this command
     * @return Available Options for this command
     * @see org.apache.commons.cli.Options
     */
    Options getOptions();

    /**
     * Adds an argument to the command.
     * @param arg The argument to send to the command.
     */
    void addArgument(String arg);

    /**
     * Adds a list of arguments to the command.
     * @param args The arguments to add to the command.
     */
    void addArguments(Collection<String> args);

    /**
     * Sets the output stream for the command 
     */
    void outputToFile(File outputFile, boolean append);

    /**
     * Executes the command.
     * @throws UsageException if usage is incorrect
     */
    Void call() throws UsageException;

}