Skip to content

Commit 9fd2130

Browse files
Modify Command interface to include default methods
Updated the execute method to throw IOException and added default methods for description and usage.
1 parent 1f47750 commit 9fd2130

1 file changed

Lines changed: 20 additions & 14 deletions

File tree

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

3+
import java.io.IOException;
4+
35
/**
46
* Represents a shell command that can be executed inside the MyCMD shell.
57
* Implementations perform their operation when {@link #execute(String[], ShellContext)} is called.
@@ -8,19 +10,23 @@ public interface Command {
810
/**
911
* Execute the command.
1012
*
11-
* <p>Implementations should perform all output to standard output or use the provided
12-
* {@link ShellContext} for interactions that depend on the shell state (for example,
13-
* changing the current directory).</p>
14-
*
15-
* @param args command-line style arguments passed to the command. May be empty but
16-
* will not be null.
17-
* @param context current shell context containing state such as the current working
18-
* directory. Implementations may read and/or modify this context.
19-
* @throws Exception if the command cannot complete successfully. The caller (shell)
20-
* is responsible for catching and reporting exceptions.
21-
*
22-
* @implNote Common concrete commands include `date` and `time` which simply print the
23-
* current date/time to standard output. See their implementations for formatting details.
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.
16+
*/
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.
2428
*/
25-
void execute(String[] args, ShellContext context);
29+
default String usage() {
30+
return "";
31+
}
2632
}

0 commit comments

Comments
 (0)