Skip to content

Commit e5bf631

Browse files
committed
refactor: replace magic strings with command constants (fixes #4)
1 parent 16c762d commit e5bf631

File tree

1 file changed

+69
-33
lines changed

1 file changed

+69
-33
lines changed

src/main/java/com/mycmd/App.java

Lines changed: 69 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -73,40 +73,76 @@ private static String resolveAliases(String input, ShellContext context) {
7373
return input;
7474
}
7575

76+
public final class CommandNames {
77+
private CommandNames() {}
78+
public static final String DIR = "dir";
79+
public static final String CD = "cd";
80+
public static final String ECHO = "echo";
81+
public static final String MKDIR = "mkdir";
82+
public static final String RMDIR = "rmdir";
83+
public static final String COPY = "copy";
84+
public static final String DEL = "del";
85+
public static final String TYPE = "type";
86+
public static final String CLS = "cls";
87+
public static final String HELP = "help";
88+
public static final String EXIT = "exit";
89+
public static final String VER = "ver";
90+
public static final String TITLE = "title";
91+
public static final String COLOR = "color";
92+
public static final String HOSTNAME = "hostname";
93+
public static final String WHOAMI = "whoami";
94+
public static final String TOUCH = "touch";
95+
public static final String TIME = "time";
96+
public static final String TASKLIST = "tasklist";
97+
public static final String TREE = "tree";
98+
public static final String DATE = "date";
99+
public static final String HISTORY = "history";
100+
public static final String PING = "ping";
101+
public static final String TELNET = "telnet";
102+
public static final String PWD = "pwd";
103+
public static final String UPTIME = "uptime";
104+
public static final String CLEARHISTORY = "clearhistory";
105+
public static final String IPCONFIG = "ipconfig";
106+
public static final String ALIAS = "alias";
107+
public static final String UNALIAS = "unalias";
108+
public static final String RENAME = "rename";
109+
public static final String SET = "set";
110+
}
76111
private static void registerCommands(Map<String, Command> commands) {
77-
commands.put("dir", new DirCommand());
78-
commands.put("cd", new CdCommand());
79-
commands.put("echo", new EchoCommand());
80-
commands.put("mkdir", new MkdirCommand());
81-
commands.put("rmdir", new RmdirCommand());
82-
commands.put("copy", new CopyCommand());
83-
commands.put("del", new DelCommand());
84-
commands.put("type", new TypeCommand());
85-
commands.put("cls", new ClsCommand());
86-
commands.put("help", new HelpCommand(commands));
87-
commands.put("exit", new ExitCommand());
88-
commands.put("ver", new VersionCommand());
89-
commands.put("title", new TitleCommand());
90-
commands.put("color", new ColorCommand());
91-
commands.put("hostname", new HostnameCommand());
92-
commands.put("whoami", new WhoamiCommand());
93-
commands.put("touch", new TouchCommand());
94-
commands.put("time", new TimeCommand());
95-
commands.put("tasklist", new TasklistCommand());
96-
commands.put("tree", new TreeCommand());
97-
commands.put("date", new DateCommand());
98-
commands.put("history", new HistoryCommand());
99-
commands.put("ping", new PingCommand());
100-
commands.put("telnet", new TelnetCommand());
101-
commands.put("pwd", new PwdCommand());
102-
commands.put("uptime", new UptimeCommand());
103-
commands.put("clearhistory", new ClearHistoryCommand());
104-
commands.put("ipconfig", new IpConfig());
105-
commands.put("alias", new AliasCommand());
106-
commands.put("unalias", new UnaliasCommand());
107-
commands.put("rename", new RenameCommand());
108-
commands.put("set", new SetCommand());
109-
}
112+
commands.put(CommandNames.DIR, new DirCommand());
113+
commands.put(CommandNames.CD, new CdCommand());
114+
commands.put(CommandNames.ECHO, new EchoCommand());
115+
commands.put(CommandNames.MKDIR, new MkdirCommand());
116+
commands.put(CommandNames.RMDIR, new RmdirCommand());
117+
commands.put(CommandNames.COPY, new CopyCommand());
118+
commands.put(CommandNames.DEL, new DelCommand());
119+
commands.put(CommandNames.TYPE, new TypeCommand());
120+
commands.put(CommandNames.CLS, new ClsCommand());
121+
commands.put(CommandNames.HELP, new HelpCommand(commands));
122+
commands.put(CommandNames.EXIT, new ExitCommand());
123+
commands.put(CommandNames.VER, new VersionCommand());
124+
commands.put(CommandNames.TITLE, new TitleCommand());
125+
commands.put(CommandNames.COLOR, new ColorCommand());
126+
commands.put(CommandNames.HOSTNAME, new HostnameCommand());
127+
commands.put(CommandNames.WHOAMI, new WhoamiCommand());
128+
commands.put(CommandNames.TOUCH, new TouchCommand());
129+
commands.put(CommandNames.TIME, new TimeCommand());
130+
commands.put(CommandNames.TASKLIST, new TasklistCommand());
131+
commands.put(CommandNames.TREE, new TreeCommand());
132+
commands.put(CommandNames.DATE, new DateCommand());
133+
commands.put(CommandNames.HISTORY, new HistoryCommand());
134+
commands.put(CommandNames.PING, new PingCommand());
135+
commands.put(CommandNames.TELNET, new TelnetCommand());
136+
commands.put(CommandNames.PWD, new PwdCommand());
137+
commands.put(CommandNames.UPTIME, new UptimeCommand());
138+
commands.put(CommandNames.CLEARHISTORY, new ClearHistoryCommand());
139+
commands.put(CommandNames.IPCONFIG, new IpConfig());
140+
commands.put(CommandNames.ALIAS, new AliasCommand());
141+
commands.put(CommandNames.UNALIAS, new UnaliasCommand());
142+
commands.put(CommandNames.RENAME, new RenameCommand());
143+
commands.put(CommandNames.SET, new SetCommand());
144+
}
145+
110146
}
111147

112148

0 commit comments

Comments
 (0)