Skip to content

Commit da25985

Browse files
Merge pull request #87 from HossamSaberr/feat/add-lombok
Feat/add lombok
2 parents add7dbb + d232cbd commit da25985

File tree

2 files changed

+60
-41
lines changed

2 files changed

+60
-41
lines changed

pom.xml

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,33 @@
1717
<maven.compiler.target>17</maven.compiler.target>
1818
</properties>
1919

20+
<dependencies>
21+
<dependency>
22+
<groupId>org.projectlombok</groupId>
23+
<artifactId>lombok</artifactId>
24+
<version>1.18.32</version>
25+
<scope>provided</scope>
26+
</dependency>
27+
</dependencies>
2028
<build>
2129
<plugins>
22-
<!-- Creates executable jar -->
30+
<plugin>
31+
<groupId>org.apache.maven.plugins</groupId>
32+
<artifactId>maven-compiler-plugin</artifactId>
33+
<version>3.11.0</version>
34+
<configuration>
35+
<source>${maven.compiler.source}</source>
36+
<target>${maven.compiler.target}</target>
37+
<annotationProcessorPaths>
38+
<path>
39+
<groupId>org.projectlombok</groupId>
40+
<artifactId>lombok</artifactId>
41+
<version>1.18.32</version>
42+
</path>
43+
</annotationProcessorPaths>
44+
</configuration>
45+
</plugin>
46+
2347
<plugin>
2448
<groupId>org.apache.maven.plugins</groupId>
2549
<artifactId>maven-jar-plugin</artifactId>
@@ -34,4 +58,4 @@
3458
</plugin>
3559
</plugins>
3660
</build>
37-
</project>
61+
</project>

src/main/java/com/mycmd/ShellContext.java

Lines changed: 34 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,29 @@
11
package com.mycmd;
22

3+
import lombok.Getter;
4+
import lombok.Setter;
5+
import lombok.NonNull;
6+
import lombok.AccessLevel;
37
import java.io.*;
48
import java.util.*;
59
import java.time.Instant;
610

11+
@Getter(AccessLevel.PUBLIC)
712
public class ShellContext {
13+
14+
@Setter
15+
@NonNull
816
private File currentDir;
917
private List<String> history;
1018
private Map<String, String> aliases;
19+
1120
private static final String ALIAS_FILE = ".mycmd_aliases";
1221
private static final int MAX_HISTORY = 100;
22+
1323
private final List<String> commandHistory;
14-
private final Instant startTime;
24+
private final Instant startTime;
25+
26+
private final Map<String, String> envVars = new HashMap<>();
1527

1628
public ShellContext() {
1729
this.currentDir = new File(System.getProperty("user.dir"));
@@ -22,39 +34,34 @@ public ShellContext() {
2234
loadAliases();
2335
}
2436

25-
public File getCurrentDir() {
26-
return currentDir;
27-
}
28-
29-
public void setCurrentDir(File dir) {
30-
this.currentDir = dir;
31-
}
3237

3338
public void addToHistory(String command) {
3439
history.add(command);
35-
commandHistory.add(command); // Add to command history
40+
commandHistory.add(command);
3641
if (history.size() > MAX_HISTORY) {
3742
history.remove(0);
3843
}
3944
}
4045

46+
47+
/** RETAINED FOR SAFETY: Returns a DEFENSIVE COPY instead of the raw Map. */
4148
public List<String> getHistory() {
4249
return new ArrayList<>(history);
4350
}
4451

45-
public List<String> getCommandHistory() {
46-
return commandHistory;
52+
public Map<String, String> getAliases() {
53+
return new HashMap<>(aliases);
4754
}
48-
49-
public Instant getStartTime() {
50-
return startTime;
55+
56+
public Map<String, String> getEnvVars() {
57+
return new HashMap<>(envVars);
5158
}
5259

60+
5361
public void clearHistory() {
5462
history.clear();
5563
}
5664

57-
// Alias management methods
5865
public void addAlias(String name, String command) {
5966
aliases.put(name, command);
6067
saveAliases();
@@ -64,21 +71,26 @@ public void removeAlias(String name) {
6471
aliases.remove(name);
6572
saveAliases();
6673
}
67-
74+
6875
public String getAlias(String name) {
6976
return aliases.get(name);
7077
}
7178

72-
public Map<String, String> getAliases() {
73-
return new HashMap<>(aliases);
74-
}
75-
7679
public boolean hasAlias(String name) {
7780
return aliases.containsKey(name);
7881
}
7982

83+
public void setEnvVar(String key, String value) {
84+
envVars.put(key, value);
85+
}
86+
87+
public String getEnvVar(String key) {
88+
return envVars.get(key);
89+
}
90+
8091
private void loadAliases() {
8192
File aliasFile = new File(System.getProperty("user.home"), ALIAS_FILE);
93+
// ... (method body remains the same)
8294
if (!aliasFile.exists()) {
8395
return;
8496
}
@@ -104,6 +116,7 @@ private void loadAliases() {
104116

105117
private void saveAliases() {
106118
File aliasFile = new File(System.getProperty("user.home"), ALIAS_FILE);
119+
// ... (method body remains the same)
107120
try (BufferedWriter writer = new BufferedWriter(new FileWriter(aliasFile))) {
108121
writer.write("# MyCMD Aliases Configuration\n");
109122
writer.write("# Format: aliasName=command\n\n");
@@ -130,22 +143,4 @@ public File resolvePath(String path) {
130143
return new File(currentDir, path);
131144
}
132145
}
133-
134-
// environmental variable map
135-
// author: Kaveesha Fernando
136-
// date: 2024-06-10
137-
private final Map<String, String> envVars = new HashMap<>();
138-
139-
public void setEnvVar(String key, String value) {
140-
envVars.put(key, value);
141-
}
142-
143-
public String getEnvVar(String key) {
144-
return envVars.get(key);
145-
}
146-
147-
public Map<String, String> getEnvVars() {
148-
return new HashMap<>(envVars);
149-
}
150-
151-
}
146+
}

0 commit comments

Comments
 (0)