mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-12-22 16:41:46 +03:00
[DOC] Документация к Command/CommandHandler
This commit is contained in:
parent
5f6da3a638
commit
31356af213
2 changed files with 50 additions and 0 deletions
|
@ -6,6 +6,9 @@
|
|||
import pro.gravit.utils.helper.VerifyHelper;
|
||||
|
||||
public abstract class Command {
|
||||
/**
|
||||
* List of available subcommands
|
||||
*/
|
||||
public Map<String, Command> childCommands;
|
||||
|
||||
public Command() {
|
||||
|
@ -38,11 +41,24 @@ protected static UUID parseUUID(String s) throws CommandException {
|
|||
|
||||
public abstract String getUsageDescription();
|
||||
|
||||
/**
|
||||
* Creates a JLine candidate that appears in the list of available options when you press TAB
|
||||
* @param category this command category
|
||||
* @param commandName this command name
|
||||
* @return JLine Candidate
|
||||
*/
|
||||
public Candidate buildCandidate(CommandHandler.Category category, String commandName)
|
||||
{
|
||||
return new Candidate(commandName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of available options for the next word for the current command.
|
||||
* @param words list all user words
|
||||
* @param wordIndex current word index
|
||||
* @param word current word
|
||||
* @return list of available Candidate
|
||||
*/
|
||||
public List<Candidate> complete(List<String> words, int wordIndex, String word)
|
||||
{
|
||||
if(wordIndex == 0)
|
||||
|
@ -64,6 +80,12 @@ public List<Candidate> complete(List<String> words, int wordIndex, String word)
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Transfer control to subcommands
|
||||
* @param args command arguments(includes subcommand name)
|
||||
* @throws Exception
|
||||
* Error executing command
|
||||
*/
|
||||
public void invokeSubcommands(String... args) throws Exception
|
||||
{
|
||||
verifyArgs(args, 1);
|
||||
|
@ -73,6 +95,12 @@ public void invokeSubcommands(String... args) throws Exception
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Run current command
|
||||
* @param args command arguments
|
||||
* @throws Exception
|
||||
* Error executing command
|
||||
*/
|
||||
public abstract void invoke(String... args) throws Exception;
|
||||
|
||||
|
||||
|
|
|
@ -90,6 +90,12 @@ public Command findCommand(String name) {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Reads a line from the console
|
||||
* @return command line
|
||||
* @throws IOException
|
||||
* Internal Error
|
||||
*/
|
||||
public abstract String readLine() throws IOException;
|
||||
|
||||
private void readLoop() throws IOException {
|
||||
|
@ -133,6 +139,12 @@ public interface CommandWalk {
|
|||
void walk(Category category, String name, Command command);
|
||||
}
|
||||
|
||||
/**
|
||||
* Walk all categories
|
||||
* Categories are sorted in the order they are added.
|
||||
* The base category is walked last
|
||||
* @param callback your callback
|
||||
*/
|
||||
public void walk(CommandWalk callback) {
|
||||
for (CommandHandler.Category category : getCategories()) {
|
||||
for (Map.Entry<String, Command> entry : category.category.commandsMap().entrySet())
|
||||
|
@ -150,8 +162,18 @@ public List<Category> getCategories() {
|
|||
return categories;
|
||||
}
|
||||
|
||||
/**
|
||||
* If supported, sends a bell signal to the console
|
||||
* @throws IOException
|
||||
* Internal Error
|
||||
*/
|
||||
public abstract void bell() throws IOException;
|
||||
|
||||
|
||||
/**
|
||||
* Cleans the console
|
||||
* @throws IOException
|
||||
* Internal Error
|
||||
*/
|
||||
public abstract void clear() throws IOException;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue