Skip to content

Commit

Permalink
#737: Added cd command to shell commandlet (#748)
Browse files Browse the repository at this point in the history
  • Loading branch information
leonrohne27 authored Nov 29, 2024
1 parent cd88c4f commit 9ad21db
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
4 changes: 3 additions & 1 deletion 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/637[#637]: Added option to disable updates
* https://github.com/devonfw/IDEasy/issues/764[#764]: IDEasy not working properly in CMD
* https://github.com/devonfw/IDEasy/issues/81[#81]: Implement Toolcommandlet for Kubernetes
* https://github.com/devonfw/IDEasy/issues/737[#737]: Adds cd command to ide shell
* https://github.com/devonfw/IDEasy/issues/758[#758]: Create status commandlet
* https://github.com/devonfw/IDEasy/issues/754[#754]: Again messages break processable command output

Expand All @@ -33,7 +34,8 @@ Release with new features and bugfixes:
* https://github.com/devonfw/IDEasy/issues/632[#632]: Add .editorconfig to settings workspaces
* https://github.com/devonfw/IDEasy/issues/415[#415]: Added a message that will inform the user for what process he will need to enter his sudo-password
* https://github.com/devonfw/IDEasy/issues/708[#708]: Open vscode in workspace path
* https://github.com/devonfw/IDEasy/issues/608[#608]: Enhanced error messages. Now logs missing command output and error messages
* https://github.com/devonfw/IDEasy/issues/608[#608]: Enhanced error messages.
Now logs missing command output and error messages
* https://github.com/devonfw/IDEasy/issues/715[#715]: Show "cygwin is not supported" message for cygwin users
* https://github.com/devonfw/IDEasy/issues/745[#745]: Maven install fails with NPE

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.devonfw.tools.ide.commandlet;

import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Iterator;

import org.fusesource.jansi.AnsiConsole;
Expand Down Expand Up @@ -79,13 +81,13 @@ public void run() {

// TODO: implement TailTipWidgets, see: https://github.com/devonfw/IDEasy/issues/169

String prompt = "ide> ";
String rightPrompt = null;
String line;

AnsiConsole.systemInstall();
while (true) {
try {
String prompt = context.getCwd() + "$ ide ";
line = reader.readLine(prompt, rightPrompt, (MaskingCallback) null, null);
line = line.trim();
if (line.equals("exit")) {
Expand Down Expand Up @@ -129,9 +131,37 @@ private int runCommand(String args) {
String[] arguments = args.split(" ", 0);
CliArguments cliArgs = new CliArguments(arguments);
cliArgs.next();

if ("cd".equals(arguments[0])) {
return changeDirectory(cliArgs);
}

return ((AbstractIdeContext) this.context).run(cliArgs);
}

private int changeDirectory(CliArguments cliArgs) {
if (!cliArgs.hasNext()) {
Path homeDir = this.context.getUserHome();
context.setCwd(homeDir, context.getWorkspaceName(), context.getIdeHome());
return 0;
}

String targetDir = String.valueOf(cliArgs.next());
Path path = Paths.get(targetDir);

// If the given path is relative, resolve it relative to the current directory
if (!path.isAbsolute()) {
path = context.getCwd().resolve(targetDir).normalize();
}

if (context.getFileAccess().isExpectedFolder(path)) {
context.setCwd(path, context.getWorkspaceName(), context.getIdeHome());
return 0;
} else {
return 1;
}
}

/**
* @param argument the current {@link CliArgument} (position) to match.
* @param commandlet the potential {@link Commandlet} to match.
Expand Down

0 comments on commit 9ad21db

Please sign in to comment.