use of com.jetbrains.commandInterface.command.Command in project intellij-community by JetBrains.
the class CommandLineFile method findRealCommand.
/**
* Tries to find real command used in this file.
* You need to first inject list of {@link #setCommands(List)}.
*
* @return Command if found and available, or null if command can't be parsed or bad command.
*/
@Override
@Nullable
public Command findRealCommand() {
final String command = getCommand();
final List<Command> commands = getCommands();
if (commands == null || command == null) {
return null;
}
for (final Command realCommand : commands) {
if (realCommand.getName().equals(command)) {
return realCommand;
}
}
return null;
}
use of com.jetbrains.commandInterface.command.Command in project intellij-community by JetBrains.
the class CommandLineDocumentationProvider method findHelp.
/**
* Searches for help text for certain element
*
* @param element element to search help for
* @return help or
*/
@Nullable
private static Help findHelp(@NotNull final PsiElement element) {
if (!(element instanceof CommandLinePart)) {
return null;
}
final CommandLinePart commandLinePart = (CommandLinePart) element;
final Command realCommand = commandLinePart.findRealCommand();
if (realCommand == null) {
return null;
}
final CommandLineElement commandLineElement = PyUtil.as(element, CommandLineElement.class);
if (commandLineElement == null) {
return null;
}
final MyCommandHelpObtainer helpObtainer = new MyCommandHelpObtainer();
commandLineElement.accept(helpObtainer);
return helpObtainer.myResultHelp;
}
use of com.jetbrains.commandInterface.command.Command in project intellij-community by JetBrains.
the class ValidationResultImpl method create.
/**
* Creates validation result by file
* @param file file to validate
* @return validation result or null if file has no command or command is unknown
*/
@Nullable
static ValidationResult create(final CommandLineFile file) {
final Command command = file.findRealCommand();
if (command == null) {
return null;
}
final ValidationResultImpl validationLayout = new ValidationResultImpl(command);
file.acceptChildren(validationLayout);
return validationLayout;
}
use of com.jetbrains.commandInterface.command.Command in project intellij-community by JetBrains.
the class CommandModeConsumer method consume.
@Override
public void consume(final String t) {
/**
* We need to: 1) parse input 2) fetch command 3) split its arguments.
*/
final PsiFileFactory fileFactory = PsiFileFactory.getInstance(myModule.getProject());
final CommandLineFile file = PyUtil.as(fileFactory.createFileFromText(CommandLineLanguage.INSTANCE, t), CommandLineFile.class);
if (file == null) {
return;
}
final String commandName = file.getCommand();
final List<String> commandAndArgs = Arrays.asList(EMPTY_SPACE.split(file.getText().trim()));
// 1 because we need to remove command which is on the first place
final List<String> args = (commandAndArgs.size() > 1 ? commandAndArgs.subList(1, commandAndArgs.size()) : Collections.<String>emptyList());
for (final Command command : myCommands) {
if (command.getName().equals(commandName)) {
command.execute(commandName, myModule, args, myConsole);
return;
}
}
if (myDefaultExecutor != null && !commandAndArgs.isEmpty()) {
// Unknown command execution is delegated to default executor
myDefaultExecutor.execute(commandAndArgs.get(0), myModule, args, myConsole);
} else {
myConsole.print(PyBundle.message("commandLine.commandNotFound", commandName), ConsoleViewContentType.ERROR_OUTPUT);
myConsole.print("", ConsoleViewContentType.SYSTEM_OUTPUT);
}
}
use of com.jetbrains.commandInterface.command.Command in project intellij-community by JetBrains.
the class CommandLineCommandReference method getVariants.
@NotNull
@Override
public Object[] getVariants() {
final CommandLineFile file = getCommandLineFile();
if (file == null) {
return EMPTY_ARRAY;
}
final List<Command> commands = file.getCommands();
if (commands == null) {
return EMPTY_ARRAY;
}
final LookupWithIndentsBuilder result = new LookupWithIndentsBuilder();
for (final Command command : commands) {
final LookupElementBuilder lookupElementBuilder = LookupElementBuilder.create(command.getName());
final Help help = command.getHelp(true);
result.addElement(lookupElementBuilder, (help != null ? help.getHelpString() : null));
}
return result.getResult();
}
Aggregations