Skip to content

Commit e23aebf

Browse files
Refactor: Update PathCommand.java
1 parent 4b5a9ca commit e23aebf

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/main/java/com/mycmd/commands/PathCommand.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ public class PathCommand implements Command {
1515
public void execute(String[] args, ShellContext context) throws IOException {
1616
if (args.length == 0) {
1717
// Display current PATH
18-
String path = System.getenv("PATH");
18+
String path = context.getEnvVar("PATH");
19+
if (path == null || path.isEmpty()) {
20+
path = System.getenv("PATH");
21+
}
22+
1923
if (path != null) {
2024
System.out.println("PATH=" + path);
2125
} else {
@@ -31,8 +35,10 @@ public void execute(String[] args, ShellContext context) throws IOException {
3135
String newPath = String.join(" ", args);
3236

3337
if (newPath.equalsIgnoreCase(";")) {
38+
context.setEnvVar("PATH", "");
3439
System.out.println("PATH cleared (session only)");
3540
} else {
41+
context.setEnvVar("PATH", newPath);
3642
System.out.println("PATH set to: " + newPath + " (session only)");
3743
}
3844
}

0 commit comments

Comments
 (0)