Skip to content

Commit 8b24c05

Browse files
committed
Commands Base Setup
1 parent 9bfeafe commit 8b24c05

File tree

6 files changed

+35
-15
lines changed

6 files changed

+35
-15
lines changed

src/com/unixtools/Main.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
package com.unixtools;
22

3+
import com.unixtools.core.CommandExecutor;
4+
35
public class Main {
4-
6+
public static void main(String[] args) {
7+
if (args.length == 0) {
8+
System.out.println("No command provided.");
9+
return;
10+
}
11+
12+
String commandName = args[0];
13+
String[] commandArgs = new String[args.length - 1];
14+
System.arraycopy(args, 1, commandArgs, 0, args.length - 1);
15+
16+
CommandExecutor executor = new CommandExecutor();
17+
executor.executeCommand(commandName, commandArgs);
18+
}
519
}

src/com/unixtools/common/Constants.java

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/com/unixtools/common/Utils.java

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/com/unixtools/core/Command.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
package com.unixtools.core;
22

3-
public class Command {
4-
3+
public interface Command {
4+
void execute(String[] args);
55
}
Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
package com.unixtools.core;
22

33
public class CommandExecutor {
4-
4+
public void executeCommand(String commandName, String[] args) {
5+
Command command = CommandFactory.getCommand(commandName);
6+
if (command != null) {
7+
command.execute(args);
8+
} else {
9+
System.out.println("Command not found.");
10+
}
11+
}
512
}
Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
package com.unixtools.core;
22

3+
import com.unixtools.command.filemanagement.LsCommand;
4+
35
public class CommandFactory {
4-
6+
public static Command getCommand(String commandName) {
7+
switch (commandName) {
8+
case "ls":
9+
return new LsCommand();
10+
default:
11+
return null;
12+
}
13+
}
514
}

0 commit comments

Comments
 (0)