-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
55 lines (48 loc) · 1.77 KB
/
Main.java
File metadata and controls
55 lines (48 loc) · 1.77 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package IO;
import java.io.File;
import java.util.ArrayList;
import java.util.Scanner;
public class Main {
public static File wd = new File(System.getProperty("user.dir"));
public static final Scanner scanner = new Scanner(System.in);
public static void main(String[] args) {
ArrayList<Command> commands = new ArrayList<>();
// használt commandok
commands.add(new PwdCommand());
commands.add(new LsCommand());
commands.add(new CdCommand());
commands.add(new RmCommand());
commands.add(new MkDirCommand());
commands.add(new MvCommand());
commands.add(new CpCommand());
commands.add(new TailCommand());
commands.add(new CatCommand());
commands.add(new LengthCommand());
commands.add(new HeadCommand());
commands.add(new WcCommand());
commands.add(new GrepCommand());
System.out.println("Started..." + "\n Type *exit* for closing");
while (true) {
String input = scanner.nextLine();
// kilépés ága exitre
if ("exit".equals(input.toLowerCase())) {
break;
}
// végigiterálunk commands arraylisten keresve a parancsunk, ha megtaláljuk és
// helyes lefuttatjuk
String[] parts = input.split(" "); // pl: "ls l"(sor) -> ["ls", "l"](tömb)
boolean found = false;
for (Command command : commands) {
if (command.getName().equals(parts[0])) {
command.action(parts);
found = true;
break;
}
}
if (!found) {
System.out.println("Unknown command!");
}
}
scanner.close();
}
}