Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -21,6 +21,7 @@ Release with new features and bugfixes:
* https://github.com/devonfw/IDEAsy/issues/2181[#2181]: Merged the VsCode and VsCodium plugin folder and added excluded-editions as an option for plugins
* https://github.com/devonfw/IDEasy/issues/2145[#2145]: Improve documentation on symlink regarding ide ln
* https://github.com/devonfw/IDEasy/issues/2235[#2235]: Language flag in cli dosn't take effect in some terminals
* 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/2136[#2136]: Add Support for Ruby URL Updater for Linux and macOS
* https://github.com/devonfw/IDEasy/issues/825[#825]: Add commandlet for GC Log Analyzer

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();
}
}
Loading