File tree Expand file tree Collapse file tree 3 files changed +53
-0
lines changed
Expand file tree Collapse file tree 3 files changed +53
-0
lines changed Original file line number Diff line number Diff line change 11package com .mycmd ;
22
3+ /**
4+ * Represents a shell command that can be executed inside the MyCMD shell.
5+ * Implementations perform their operation when {@link #execute(String[], ShellContext)} is called.
6+ */
37public interface Command {
8+ /**
9+ * Execute the command.
10+ *
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.
24+ */
425 void execute (String [] args , ShellContext context );
526}
Original file line number Diff line number Diff line change 44import com .mycmd .ShellContext ;
55import java .time .LocalDate ;
66
7+ /**
8+ * Command that prints the current date to standard output.
9+ *
10+ * <p>This command does not use the provided {@link ShellContext} but keeps the
11+ * parameter to conform to the {@link Command} contract. The output is produced
12+ * using {@link LocalDate#now()} and printed in ISO-8601 format (yyyy-MM-dd).</p>
13+ */
714public class DateCommand implements Command {
15+ /**
16+ * Print the current date.
17+ *
18+ * @param args ignored for this command; may be empty or contain unused tokens.
19+ * @param context the current shell context; not used by this command.
20+ */
821 @ Override
922 public void execute (String [] args , ShellContext context ) {
1023 System .out .println ("The current date is: " + java .time .LocalDate .now ());
Original file line number Diff line number Diff line change 55import java .time .LocalTime ;
66import java .time .format .DateTimeFormatter ;
77
8+ /**
9+ * Command that prints the current local time to standard output using a simple
10+ * custom formatter.
11+ *
12+ * <p>The time is formatted with the pattern "H.mm.ss.SS" where:
13+ * <ul>
14+ * <li>H - hour-of-day (0-23)</li>
15+ * <li>mm - minute-of-hour</li>
16+ * <li>ss - second-of-minute</li>
17+ * <li>SS - fraction-of-second (two digits)</li>
18+ * </ul>
19+ * Example output: "The current time is: 13.5.07.12"</p>
20+ */
821public class TimeCommand implements Command {
22+ /**
23+ * Print the current time.
24+ *
25+ * @param args ignored for this command; may be empty or contain unused tokens.
26+ * @param context the current shell context; not used by this command.
27+ */
928 @ Override
1029 public void execute (String [] args , ShellContext context ) {
1130 LocalTime now = LocalTime .now ();
You can’t perform that action at this time.
0 commit comments