forked from Drive-for-Java/MyCMD
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEchoCommand.java
More file actions
38 lines (34 loc) · 945 Bytes
/
Copy pathEchoCommand.java
File metadata and controls
38 lines (34 loc) · 945 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package com.mycmd.commands;
import com.mycmd.Command;
import com.mycmd.ShellContext;
/**
* Displays text messages to the console output.
*
* This command prints all provided arguments to standard output, joining
* multiple arguments with spaces. When called without arguments, it prints
* a blank line.
*
* Usage:
* - echo : Print a blank line
* - echo message : Print the message to console
*
* Multiple words are automatically joined with spaces between them.
*/
public class EchoCommand implements Command {
@Override
public void execute(String[] args, ShellContext context) {
if (args.length == 0) {
System.out.println();
} else {
System.out.println(String.join(" ", args));
}
}
@Override
public String description() {
return "Display a line of text";
}
@Override
public String usage() {
return "echo <text>";
}
}