use of com.jetbrains.commandInterface.commandLine.psi.CommandLineFile 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.commandLine.psi.CommandLineFile 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();
}
use of com.jetbrains.commandInterface.commandLine.psi.CommandLineFile in project intellij-community by JetBrains.
the class CommandLineArgsTest method testNoMoreArgs.
/**
* Ensures argument is not returned if not required
*/
public void testNoMoreArgs() throws Exception {
CommandTestTools.initFileType();
final CommandLineFile file = CommandTestTools.createFileByText(myFixture, "command foo bar spam eggs");
final ValidationResult validationResult = file.getValidationResult();
assert validationResult != null : "validation failed";
Assert.assertNull("Argument returned while should not", validationResult.getNextArg());
}
use of com.jetbrains.commandInterface.commandLine.psi.CommandLineFile in project intellij-community by JetBrains.
the class CommandLineInspectionTest method doTest.
/**
* Enables inspection on testName.cmdline and checks it.
*/
private void doTest() {
final PsiFile file = myFixture.configureByFile(getTestName(true) + '.' + CommandLineFileType.EXTENSION);
Assert.assertSame("Bad file type!", CommandLineFile.class, file.getClass());
final CommandLineFile commandLineFile = (CommandLineFile) file;
commandLineFile.setCommands(CommandTestTools.createCommands());
myFixture.enableInspections(CommandLineInspection.class);
myFixture.checkHighlighting();
}
use of com.jetbrains.commandInterface.commandLine.psi.CommandLineFile in project intellij-community by JetBrains.
the class CommandTestTools method createFileByText.
/**
* Creates command file by text and {@link #createCommands() fills it with commands}
* @param testFixture fixture
* @param text command text
* @return command file
* @see #createCommands()
*/
@NotNull
static CommandLineFile createFileByText(@NotNull final CodeInsightTestFixture testFixture, @NotNull final String text) {
final CommandLineFile file = (CommandLineFile) testFixture.configureByText(CommandLineFileType.INSTANCE, text);
file.setCommands(createCommands());
return file;
}
Aggregations