Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#737: Added cd command to shell commandlet #748

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
3be67d0
#737: Added cd command to shell commandlet
leonrohne27 Nov 6, 2024
60f2e8a
Merge branch 'main' into implement/737-add-cd-command-to-shell-comman…
leonrohne27 Nov 6, 2024
02cdeb0
Merge branch 'main' into implement/737-add-cd-command-to-shell-comman…
jan-vcapgemini Nov 7, 2024
2d41161
Merge branch 'main' into implement/737-add-cd-command-to-shell-comman…
jan-vcapgemini Nov 11, 2024
bad672f
Merge branch 'main' into implement/737-add-cd-command-to-shell-comman…
jan-vcapgemini Nov 14, 2024
b85ca18
Merge branch 'main' into implement/737-add-cd-command-to-shell-comman…
jan-vcapgemini Nov 18, 2024
51dd0c2
Update cli/src/main/java/com/devonfw/tools/ide/commandlet/ShellComman…
leonrohne27 Nov 19, 2024
0bd754c
Update cli/src/main/java/com/devonfw/tools/ide/commandlet/ShellComman…
leonrohne27 Nov 19, 2024
1af2948
#737: optimized cd command
leonrohne27 Nov 19, 2024
ec4d5f6
#737: optimized cd command
leonrohne27 Nov 19, 2024
06e9b8a
#737: Added Changelog entry
leonrohne27 Nov 19, 2024
17b5888
Merge branch 'main' into implement/737-add-cd-command-to-shell-comman…
jan-vcapgemini Nov 19, 2024
bcdd9bf
Merge branch 'main' into implement/737-add-cd-command-to-shell-comman…
jan-vcapgemini Nov 20, 2024
2e86be8
Merge branch 'main' into implement/737-add-cd-command-to-shell-comman…
hohwille Nov 28, 2024
d9aba17
#737: Changed cd without args and prompt String
leonrohne27 Nov 29, 2024
6f9865c
Merge branch 'main' into implement/737-add-cd-command-to-shell-comman…
hohwille Nov 29, 2024
7a7e137
Update cli/src/main/java/com/devonfw/tools/ide/commandlet/ShellComman…
leonrohne27 Nov 29, 2024
2ca5400
#737: Added changelog entry
leonrohne27 Nov 29, 2024
613b223
#737
leonrohne27 Nov 29, 2024
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
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