From 3be67d073ef427c98bcc02124e75b1c75a5f6541 Mon Sep 17 00:00:00 2001 From: leonrohne27 Date: Wed, 6 Nov 2024 13:15:07 +0100 Subject: [PATCH 01/10] #737: Added cd command to shell commandlet Added the command cd to the shell commandlet that allows the user to switch the directory inside the ide shell --- .../tools/ide/commandlet/ShellCommandlet.java | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/cli/src/main/java/com/devonfw/tools/ide/commandlet/ShellCommandlet.java b/cli/src/main/java/com/devonfw/tools/ide/commandlet/ShellCommandlet.java index f350408a7..d41592b89 100644 --- a/cli/src/main/java/com/devonfw/tools/ide/commandlet/ShellCommandlet.java +++ b/cli/src/main/java/com/devonfw/tools/ide/commandlet/ShellCommandlet.java @@ -1,6 +1,9 @@ package com.devonfw.tools.ide.commandlet; import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; import java.util.Iterator; import org.fusesource.jansi.AnsiConsole; @@ -132,9 +135,40 @@ 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()) { + this.context.error("Error: 'cd' requires a directory argument."); + return -1; + } + + 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 = Paths.get(System.getProperty("user.dir")).resolve(path).normalize(); + } + + // Check if the path exists and is a directory + if (Files.exists(path) && Files.isDirectory(path)) { + // Set the current working directory to the new path + System.setProperty("user.dir", path.toAbsolutePath().toString()); + this.context.info("Changed directory to: " + path.toAbsolutePath()); + return 0; + } else { + this.context.error("Error: Directory not found: " + targetDir); + return -1; + } + } + /** * @param argument the current {@link CliArgument} (position) to match. * @param commandlet the potential {@link Commandlet} to match. From 51dd0c2c3958d4adeae503bc98afa337581b1707 Mon Sep 17 00:00:00 2001 From: leonrohne27 Date: Tue, 19 Nov 2024 10:23:04 +0100 Subject: [PATCH 02/10] Update cli/src/main/java/com/devonfw/tools/ide/commandlet/ShellCommandlet.java Co-authored-by: jan-vcapgemini <59438728+jan-vcapgemini@users.noreply.github.com> --- .../java/com/devonfw/tools/ide/commandlet/ShellCommandlet.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/src/main/java/com/devonfw/tools/ide/commandlet/ShellCommandlet.java b/cli/src/main/java/com/devonfw/tools/ide/commandlet/ShellCommandlet.java index 6a743a671..567b12ecb 100644 --- a/cli/src/main/java/com/devonfw/tools/ide/commandlet/ShellCommandlet.java +++ b/cli/src/main/java/com/devonfw/tools/ide/commandlet/ShellCommandlet.java @@ -151,7 +151,7 @@ private int changeDirectory(CliArguments cliArgs) { // If the given path is relative, resolve it relative to the current directory if (!path.isAbsolute()) { - path = Paths.get(System.getProperty("user.dir")).resolve(path).normalize(); + path = context.getCwd(); } // Check if the path exists and is a directory From 0bd754cdb515c2452cbd8d0ad4fbe5a3253e462e Mon Sep 17 00:00:00 2001 From: leonrohne27 Date: Tue, 19 Nov 2024 10:23:22 +0100 Subject: [PATCH 03/10] Update cli/src/main/java/com/devonfw/tools/ide/commandlet/ShellCommandlet.java Co-authored-by: jan-vcapgemini <59438728+jan-vcapgemini@users.noreply.github.com> --- .../java/com/devonfw/tools/ide/commandlet/ShellCommandlet.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/src/main/java/com/devonfw/tools/ide/commandlet/ShellCommandlet.java b/cli/src/main/java/com/devonfw/tools/ide/commandlet/ShellCommandlet.java index 567b12ecb..c3c499d77 100644 --- a/cli/src/main/java/com/devonfw/tools/ide/commandlet/ShellCommandlet.java +++ b/cli/src/main/java/com/devonfw/tools/ide/commandlet/ShellCommandlet.java @@ -157,7 +157,7 @@ private int changeDirectory(CliArguments cliArgs) { // Check if the path exists and is a directory if (Files.exists(path) && Files.isDirectory(path)) { // Set the current working directory to the new path - System.setProperty("user.dir", path.toAbsolutePath().toString()); + context.setCwd(path, context.getWorkspaceName(), context.getIdeHome()); this.context.info("Changed directory to: " + path.toAbsolutePath()); return 0; } else { From 1af2948982531b916d7c309e943dd39db7d85f29 Mon Sep 17 00:00:00 2001 From: leonrohne27 Date: Tue, 19 Nov 2024 12:03:31 +0100 Subject: [PATCH 04/10] #737: optimized cd command added current working directory path to prompt name improved existing directory check adjusted exit codes --- .../tools/ide/commandlet/ShellCommandlet.java | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/cli/src/main/java/com/devonfw/tools/ide/commandlet/ShellCommandlet.java b/cli/src/main/java/com/devonfw/tools/ide/commandlet/ShellCommandlet.java index c3c499d77..b2f66ff00 100644 --- a/cli/src/main/java/com/devonfw/tools/ide/commandlet/ShellCommandlet.java +++ b/cli/src/main/java/com/devonfw/tools/ide/commandlet/ShellCommandlet.java @@ -1,7 +1,6 @@ package com.devonfw.tools.ide.commandlet; import java.io.IOException; -import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.Iterator; @@ -82,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 = "ide " + context.getCwd() + " > "; line = reader.readLine(prompt, rightPrompt, (MaskingCallback) null, null); line = line.trim(); if (line.equals("exit")) { @@ -143,7 +142,7 @@ private int runCommand(String args) { private int changeDirectory(CliArguments cliArgs) { if (!cliArgs.hasNext()) { this.context.error("Error: 'cd' requires a directory argument."); - return -1; + return 1; } String targetDir = String.valueOf(cliArgs.next()); @@ -151,21 +150,20 @@ private int changeDirectory(CliArguments cliArgs) { // If the given path is relative, resolve it relative to the current directory if (!path.isAbsolute()) { - path = context.getCwd(); + path = context.getCwd().resolve(targetDir).normalize(); } // Check if the path exists and is a directory - if (Files.exists(path) && Files.isDirectory(path)) { + + if (context.getFileAccess().isExpectedFolder(path)) { // Set the current working directory to the new path context.setCwd(path, context.getWorkspaceName(), context.getIdeHome()); - this.context.info("Changed directory to: " + path.toAbsolutePath()); return 0; } else { - this.context.error("Error: Directory not found: " + targetDir); - return -1; + return 1; } } - + /** * @param argument the current {@link CliArgument} (position) to match. * @param commandlet the potential {@link Commandlet} to match. From ec4d5f69d2114c600ca59710fc5c8689fcacb7e6 Mon Sep 17 00:00:00 2001 From: leonrohne27 Date: Tue, 19 Nov 2024 12:25:25 +0100 Subject: [PATCH 05/10] #737: optimized cd command removed whitespace from ide prompt --- .../java/com/devonfw/tools/ide/commandlet/ShellCommandlet.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/src/main/java/com/devonfw/tools/ide/commandlet/ShellCommandlet.java b/cli/src/main/java/com/devonfw/tools/ide/commandlet/ShellCommandlet.java index b2f66ff00..a63377db5 100644 --- a/cli/src/main/java/com/devonfw/tools/ide/commandlet/ShellCommandlet.java +++ b/cli/src/main/java/com/devonfw/tools/ide/commandlet/ShellCommandlet.java @@ -87,7 +87,7 @@ public void run() { AnsiConsole.systemInstall(); while (true) { try { - String prompt = "ide " + context.getCwd() + " > "; + String prompt = "ide " + context.getCwd() + "> "; line = reader.readLine(prompt, rightPrompt, (MaskingCallback) null, null); line = line.trim(); if (line.equals("exit")) { From 06e9b8af7ae44fd99c961c35ca643bd50efbee09 Mon Sep 17 00:00:00 2001 From: leonrohne27 Date: Tue, 19 Nov 2024 12:33:16 +0100 Subject: [PATCH 06/10] #737: Added Changelog entry --- CHANGELOG.adoc | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index b35d458d6..a74e59853 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -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/737[#737]: Adds cd command to ide shell The full list of changes for this release can be found in https://github.com/devonfw/IDEasy/milestone/16?closed=1[milestone 2024.12.001]. From d9aba1773a6758700b89ea454dba791705150dbb Mon Sep 17 00:00:00 2001 From: leonrohne27 Date: Fri, 29 Nov 2024 11:17:27 +0100 Subject: [PATCH 07/10] #737: Changed cd without args and prompt String Cd without arguments now brings the user to the home path, changed the prompt String --- .../devonfw/tools/ide/commandlet/ShellCommandlet.java | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/cli/src/main/java/com/devonfw/tools/ide/commandlet/ShellCommandlet.java b/cli/src/main/java/com/devonfw/tools/ide/commandlet/ShellCommandlet.java index a63377db5..b80294555 100644 --- a/cli/src/main/java/com/devonfw/tools/ide/commandlet/ShellCommandlet.java +++ b/cli/src/main/java/com/devonfw/tools/ide/commandlet/ShellCommandlet.java @@ -87,7 +87,7 @@ public void run() { AnsiConsole.systemInstall(); while (true) { try { - String prompt = "ide " + context.getCwd() + "> "; + String prompt = context.getCwd() + "$ ide "; line = reader.readLine(prompt, rightPrompt, (MaskingCallback) null, null); line = line.trim(); if (line.equals("exit")) { @@ -141,8 +141,9 @@ private int runCommand(String args) { private int changeDirectory(CliArguments cliArgs) { if (!cliArgs.hasNext()) { - this.context.error("Error: 'cd' requires a directory argument."); - return 1; + Path homeDir = Paths.get(System.getProperty("user.home")); + context.setCwd(homeDir, context.getWorkspaceName(), context.getIdeHome()); + return 0; } String targetDir = String.valueOf(cliArgs.next()); @@ -153,10 +154,7 @@ private int changeDirectory(CliArguments cliArgs) { path = context.getCwd().resolve(targetDir).normalize(); } - // Check if the path exists and is a directory - if (context.getFileAccess().isExpectedFolder(path)) { - // Set the current working directory to the new path context.setCwd(path, context.getWorkspaceName(), context.getIdeHome()); return 0; } else { From 7a7e137d13d2a80d27e1f7fc0d3a9f25e356ea7a Mon Sep 17 00:00:00 2001 From: leonrohne27 Date: Fri, 29 Nov 2024 14:16:07 +0100 Subject: [PATCH 08/10] Update cli/src/main/java/com/devonfw/tools/ide/commandlet/ShellCommandlet.java MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Jörg Hohwiller --- .../java/com/devonfw/tools/ide/commandlet/ShellCommandlet.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/src/main/java/com/devonfw/tools/ide/commandlet/ShellCommandlet.java b/cli/src/main/java/com/devonfw/tools/ide/commandlet/ShellCommandlet.java index b80294555..a86301d52 100644 --- a/cli/src/main/java/com/devonfw/tools/ide/commandlet/ShellCommandlet.java +++ b/cli/src/main/java/com/devonfw/tools/ide/commandlet/ShellCommandlet.java @@ -141,7 +141,7 @@ private int runCommand(String args) { private int changeDirectory(CliArguments cliArgs) { if (!cliArgs.hasNext()) { - Path homeDir = Paths.get(System.getProperty("user.home")); + Path homeDir = this.context.getUserHome(); context.setCwd(homeDir, context.getWorkspaceName(), context.getIdeHome()); return 0; } From 2ca5400fb8d820e272e2e0c610cd58ffbd20d5c6 Mon Sep 17 00:00:00 2001 From: leonrohne27 Date: Fri, 29 Nov 2024 14:20:20 +0100 Subject: [PATCH 09/10] #737: Added changelog entry --- CHANGELOG.adoc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index f16a68340..f10dd4e2c 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -24,6 +24,7 @@ Release with new features and bugfixes: * 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 +* https://github.com/devonfw/IDEasy/issues/737[#754]: Added cd command to ide shell The full list of changes for this release can be found in https://github.com/devonfw/IDEasy/milestone/16?closed=1[milestone 2024.12.001]. @@ -34,7 +35,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 From 613b223093b3755cf9b31081231fca1a76bd842f Mon Sep 17 00:00:00 2001 From: leonrohne27 Date: Fri, 29 Nov 2024 14:22:07 +0100 Subject: [PATCH 10/10] #737 --- CHANGELOG.adoc | 1 - 1 file changed, 1 deletion(-) diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index f10dd4e2c..3e2023a64 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -24,7 +24,6 @@ Release with new features and bugfixes: * 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 -* https://github.com/devonfw/IDEasy/issues/737[#754]: Added cd command to ide shell The full list of changes for this release can be found in https://github.com/devonfw/IDEasy/milestone/16?closed=1[milestone 2024.12.001].