Skip to content

Commit bea6704

Browse files
Merge pull request #37 from thidaskaveesha/doc/command
Docs: Add Javadoc Comments to Public Methods in Command.java #9
2 parents 57da792 + 23a6dc2 commit bea6704

24 files changed

+338
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,26 @@
11
package 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+
*/
37
public 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
}

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,21 @@
44
import com.mycmd.ShellContext;
55
import java.io.File;
66

7+
/**
8+
* Changes the current working directory or displays the current directory path.
9+
*
10+
* This command allows navigation through the file system hierarchy. When called
11+
* without arguments, it prints the absolute path of the current directory. When
12+
* provided with a path argument, it attempts to change to that directory.
13+
*
14+
* Usage:
15+
* - cd : Display current directory
16+
* - cd path : Change to specified path (absolute or relative)
17+
* - cd .. : Navigate to parent directory
18+
*
19+
* The command handles both absolute and relative paths. Relative paths are
20+
* resolved against the current working directory stored in ShellContext.
21+
*/
722
public class CdCommand implements Command {
823
@Override
924
public void execute(String[] args, ShellContext context) {

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,17 @@
33
import com.mycmd.Command;
44
import com.mycmd.ShellContext;
55

6+
/**
7+
* Clears the console screen by printing multiple blank lines.
8+
*
9+
* This command simulates clearing the terminal screen by outputting 50 blank
10+
* lines, pushing previous content out of view. This is a simple cross-platform
11+
* approach that doesn't rely on terminal-specific control sequences.
12+
*
13+
* Usage: cls
14+
*
15+
* Note: This command does not accept any arguments.
16+
*/
617
public class ClsCommand implements Command {
718
@Override
819
public void execute(String[] args, ShellContext context) {

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,22 @@
33
import com.mycmd.Command;
44
import com.mycmd.ShellContext;
55

6+
/**
7+
* Changes the console text and background colors using ANSI escape codes.
8+
*
9+
* This command accepts a two-character hexadecimal code where the first digit
10+
* represents the background color and the second digit represents the text color.
11+
* Valid color codes are 0-9 and A-F (hexadecimal). When called without arguments,
12+
* it resets colors to terminal defaults.
13+
*
14+
* Usage:
15+
* - color : Reset to default colors
16+
* - color XY : Set background to X and text to Y (hex digits 0-F)
17+
*
18+
* Example: color 0A sets black background with bright green text.
19+
*
20+
* Note: Background and text colors cannot be the same value.
21+
*/
622
public class ColorCommand implements Command {
723
@Override
824
public void execute(String[] args, ShellContext context) {

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,20 @@
44
import com.mycmd.ShellContext;
55
import java.io.*;
66

7+
/**
8+
* Copies a file from source to destination location.
9+
*
10+
* This command reads the contents of a source file and writes it to a
11+
* destination file using buffered I/O streams for efficient copying. Both
12+
* source and destination paths are resolved relative to the current working
13+
* directory unless absolute paths are provided.
14+
*
15+
* Usage: copy source destination
16+
*
17+
* The command verifies that the source exists and is a regular file before
18+
* attempting the copy operation. If the destination file already exists, it
19+
* will be overwritten.
20+
*/
721
public class CopyCommand implements Command {
822
@Override
923
public void execute(String[] args, ShellContext context) {

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,20 @@
44
import com.mycmd.ShellContext;
55
import 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+
*/
714
public 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());

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,19 @@
44
import com.mycmd.ShellContext;
55
import java.io.File;
66

7+
/**
8+
* Deletes one or more files from the file system.
9+
*
10+
* This command accepts one or more file names as arguments and attempts to
11+
* delete each file. File paths are resolved relative to the current working
12+
* directory. The command provides feedback for each file indicating whether
13+
* the deletion was successful or if the file was not found.
14+
*
15+
* Usage: del file1 [file2 file3 ...]
16+
*
17+
* Note: This command only deletes files, not directories. Use rmdir for
18+
* directory removal.
19+
*/
720
public class DelCommand implements Command {
821
@Override
922
public void execute(String[] args, ShellContext context) {

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,21 @@
44
import com.mycmd.ShellContext;
55
import java.io.File;
66

7+
/**
8+
* Lists files and directories in the current working directory.
9+
*
10+
* This command displays all files and subdirectories within the current
11+
* directory. Directories are prefixed with angle brackets and "DIR" label,
12+
* while files are displayed with spacing for alignment.
13+
*
14+
* Usage: dir
15+
*
16+
* Output format:
17+
* - Directories: angle-bracket-DIR-angle-bracket followed by directory name
18+
* - Files: Six spaces followed by file name
19+
*
20+
* If the directory is empty or cannot be read, an appropriate message is displayed.
21+
*/
722
public class DirCommand implements Command {
823
@Override
924
public void execute(String[] args, ShellContext context) {

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,19 @@
33
import com.mycmd.Command;
44
import com.mycmd.ShellContext;
55

6+
/**
7+
* Displays text messages to the console output.
8+
*
9+
* This command prints all provided arguments to standard output, joining
10+
* multiple arguments with spaces. When called without arguments, it prints
11+
* a blank line.
12+
*
13+
* Usage:
14+
* - echo : Print a blank line
15+
* - echo message : Print the message to console
16+
*
17+
* Multiple words are automatically joined with spaces between them.
18+
*/
619
public class EchoCommand implements Command {
720
@Override
821
public void execute(String[] args, ShellContext context) {

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,18 @@
33
import com.mycmd.Command;
44
import com.mycmd.ShellContext;
55

6+
/**
7+
* Terminates the MyCMD shell application.
8+
*
9+
* This command exits the shell by calling System.exit(0), which immediately
10+
* terminates the JVM process with a success status code. A goodbye message
11+
* is displayed before exiting.
12+
*
13+
* Usage: exit
14+
*
15+
* Note: This command does not accept any arguments and exits immediately
16+
* without prompting for confirmation.
17+
*/
618
public class ExitCommand implements Command {
719
@Override
820
public void execute(String[] args, ShellContext context) {

0 commit comments

Comments
 (0)