Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ This file documents all notable changes to https://github.com/devonfw/IDEasy[IDE

Release with new features and bugfixes:

* https://github.com/devonfw/IDEasy/issues/821[#821]: Made the `ide` prefix in `ide shell` part of the editable input so it can be removed for non-IDEasy commands
* https://github.com/devonfw/IDEasy/issues/2286[#2286]: Fix SystemPath.findBinary to search extraPathEntries
* https://github.com/devonfw/IDEasy/issues/1165[#1165]: Fix automatic project import for Eclipse
* https://github.com/devonfw/IDEasy/issues/2040[#2040]: Fixed buggy workspace selection in the GUI
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public final class ShellCommandlet extends Commandlet {

private static final String EXIT_COMMAND = "exit";

private static final String IDE_PREFIX = "ide ";

/**
* The constructor.
*
Expand Down Expand Up @@ -90,9 +92,9 @@ protected void doRun() {
while (true) {
try {
String cwdPath = String.valueOf(context.getCwd());
String prompt = cwdPath + (cwdPath.length() <= 80 ? "" : System.lineSeparator()) + "$ ide ";
line = reader.readLine(prompt, rightPrompt, (MaskingCallback) null, null);
line = line.trim();
String prompt = cwdPath + (cwdPath.length() <= 80 ? "" : System.lineSeparator()) + "$ ";
line = reader.readLine(prompt, rightPrompt, (MaskingCallback) null, IDE_PREFIX);
line = normalizeLine(line);
if (EXIT_COMMAND.equals(line)) {
return;
}
Expand Down Expand Up @@ -122,6 +124,25 @@ protected void doRun() {
}
}

/**
* Strips the pre-filled {@link #IDE_PREFIX} from the given raw input line, so that a command entered after leaving the prefix untouched (e.g.
* {@code ide status}) behaves the same as if only {@code status} was entered. This allows the user to remove the prefix via backspace to enter a
* non-IDEasy command (e.g. {@code cd}) without the misleading {@code ide} prefix.
*
* @param rawLine the raw line as read from the {@link LineReader}.
* @return the normalized line ready to be passed to {@link #runCommand(String)}.
*/
static String normalizeLine(String rawLine) {

String line = rawLine.trim();
if (line.equals(IDE_PREFIX.trim())) {
return "";
} else if (line.startsWith(IDE_PREFIX)) {
return line.substring(IDE_PREFIX.length()).trim();
}
return line;
}

/**
* Converts String of arguments to array and runs the command
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.devonfw.tools.ide.commandlet;

import org.junit.jupiter.api.Test;

import com.devonfw.tools.ide.context.AbstractIdeContextTest;

/**
* Test of {@link ShellCommandlet}.
*/
class ShellCommandletTest extends AbstractIdeContextTest {

/**
* Test of {@link ShellCommandlet#normalizeLine(String)} when the pre-filled {@code ide } prefix is left untouched, so the command behaves the same as
* before this prefix was made part of the editable input line.
*/
@Test
void testNormalizeLineKeepsPrefixedCommand() {

// act & assert
assertThat(ShellCommandlet.normalizeLine("ide status")).isEqualTo("status");
assertThat(ShellCommandlet.normalizeLine("ide install java")).isEqualTo("install java");
}

/**
* Test of {@link ShellCommandlet#normalizeLine(String)} when the user removed the pre-filled {@code ide } prefix via backspace to enter a non-IDEasy
* command, e.g. {@code cd}, see <a href="https://github.com/devonfw/IDEasy/issues/821">#821</a> for reference.
*/
@Test
void testNormalizeLineWithRemovedPrefix() {

// act & assert
assertThat(ShellCommandlet.normalizeLine("cd ..")).isEqualTo("cd ..");
assertThat(ShellCommandlet.normalizeLine("exit")).isEqualTo("exit");
}

/**
* Test of {@link ShellCommandlet#normalizeLine(String)} when the user leaves an empty or unmodified prompt.
*/
@Test
void testNormalizeLineWithEmptyInput() {

// act & assert
assertThat(ShellCommandlet.normalizeLine("ide")).isEmpty();
assertThat(ShellCommandlet.normalizeLine("ide ")).isEmpty();
assertThat(ShellCommandlet.normalizeLine("")).isEmpty();
}
}