Skip to content

Commit fafba30

Browse files
author
Thidas Senavirathna
committed
fixed compiling issue
1 parent a0953e8 commit fafba30

File tree

2 files changed

+20
-24
lines changed

2 files changed

+20
-24
lines changed
Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,14 @@
11
package com.mycmd;
22

3-
import java.io.IOException;
3+
import com.mycmd.ShellContext;
44

5-
/**
6-
* Represents a shell command that can be executed inside the MyCMD shell.
7-
* Implementations perform their operation when {@link #execute(String[], ShellContext)} is called.
8-
*/
95
public interface Command {
6+
String getName();
7+
String getDescription();
108
/**
119
* Execute the command.
12-
*
13-
* @param args command-line style arguments passed to the command. May be empty but will not be null.
14-
* @param context current shell context containing state such as the current working directory.
15-
* @throws IOException if the command cannot complete successfully.
10+
* @param context shell context
11+
* @param args command arguments
1612
*/
17-
void execute(String[] args, ShellContext context) throws IOException;
18-
19-
/**
20-
* Short description of the command. Default is empty so existing implementations do not break.
21-
*/
22-
default String description() {
23-
return "";
24-
}
25-
26-
/**
27-
* Usage string for the command. Default is empty.
28-
*/
29-
default String usage() {
30-
return "";
31-
}
13+
void execute(ShellContext context, String[] args) throws Exception;
3214
}

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,23 @@
22

33
import java.io.*;
44
import java.util.*;
5+
import java.time.Instant;
56

67
public class ShellContext {
78
private File currentDir;
89
private List<String> history;
910
private Map<String, String> aliases;
1011
private static final String ALIAS_FILE = ".mycmd_aliases";
1112
private static final int MAX_HISTORY = 100;
13+
private final List<String> commandHistory;
14+
private final Instant startTime;
1215

1316
public ShellContext() {
1417
this.currentDir = new File(System.getProperty("user.dir"));
1518
this.history = new ArrayList<>();
1619
this.aliases = new HashMap<>();
20+
this.commandHistory = new ArrayList<>();
21+
this.startTime = Instant.now();
1722
loadAliases();
1823
}
1924

@@ -27,6 +32,7 @@ public void setCurrentDir(File dir) {
2732

2833
public void addToHistory(String command) {
2934
history.add(command);
35+
commandHistory.add(command); // Add to command history
3036
if (history.size() > MAX_HISTORY) {
3137
history.remove(0);
3238
}
@@ -36,6 +42,14 @@ public List<String> getHistory() {
3642
return new ArrayList<>(history);
3743
}
3844

45+
public List<String> getCommandHistory() {
46+
return commandHistory;
47+
}
48+
49+
public Instant getStartTime() {
50+
return startTime;
51+
}
52+
3953
public void clearHistory() {
4054
history.clear();
4155
}

0 commit comments

Comments
 (0)