001/*
002 * Stallion Core: A Modern Web Framework
003 *
004 * Copyright (C) 2015 - 2016 Stallion Software LLC.
005 *
006 * This program is free software: you can redistribute it and/or modify it under the terms of the
007 * GNU General Public License as published by the Free Software Foundation, either version 2 of
008 * the License, or (at your option) any later version. This program is distributed in the hope that
009 * it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
010 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
011 * License for more details. You should have received a copy of the GNU General Public License
012 * along with this program.  If not, see <http://www.gnu.org/licenses/gpl-2.0.html>.
013 *
014 *
015 *
016 */
017
018package io.stallion.boot;
019
020/**
021 * A way to implement executable actions that can be run via the command line.
022 * When you run Stallion from the command line you pass in an action
023 * as the first argument, such as "serve" or "new". Each action implements
024 * this interface, and then is added to the list of actions in
025 * io.stallion.Booter.
026 *
027 * @param <T>
028 */
029public interface StallionRunAction<T extends CommandOptionsBase> {
030
031    /**
032     * The name of the action, will be used on the command line to run the action.
033     *
034     * @return
035     */
036    public String getActionName();
037
038    /**
039     * A friendly description of what the action does, will be printed on the command-line
040     * when help is asked for.
041     *
042     * @return
043     */
044    public String getHelp();
045
046    /**
047     *
048     * Load the application context. Some actions just need the settings loaded. Other actions
049     * need the settings plus all the services and data access layers. Other actions need
050     * all the former plus need to start jobs and the async task coordinator. Call exactly
051     * what you need to load in this method.
052     *
053     * @param options
054     */
055    public void loadApp(T options);
056
057    public default String getSubActionName() {
058        return "";
059    }
060
061    /**
062     * Each action might have its own command-line arguments. Define your command-line
063     * arguments by creating a subclass of BaseCommandOptions. Then override this method
064     * to construct an instance of the subclass you created and return it.
065     *
066     * @param <T>
067     * @return
068     */
069    public default <T extends CommandOptionsBase> T newCommandOptions() {
070        return (T)new CommandOptionsBase();
071    }
072
073    /**
074     * Actually do the action.
075     *
076     * @param options
077     * @throws Exception
078     */
079    public void execute(T options) throws Exception;
080
081}