1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.ibatis.migration.commands;
17
18 import org.apache.ibatis.migration.MigrationException;
19 import org.apache.ibatis.migration.options.SelectedOptions;
20
21 public enum Commands {
22 INFO,
23
24 INIT,
25
26 BOOTSTRAP,
27
28 NEW,
29
30 UP,
31
32 DOWN,
33
34 PENDING,
35
36 SCRIPT,
37
38 VERSION,
39
40 STATUS,
41
42 REDO;
43
44 public static Command resolveCommand(String commandString, SelectedOptions selectedOptions) {
45 final String upperCasedStr = commandString.toUpperCase();
46 for (Commands command : values()) {
47 if (command.name().startsWith(upperCasedStr)) {
48 return createCommand(command, selectedOptions);
49 }
50 }
51
52 throw new MigrationException("Attempt to execute unknown command: " + commandString);
53 }
54
55 private static Command createCommand(Commands aResolvedCommand, SelectedOptions selectedOptions) {
56 switch (aResolvedCommand) {
57 case INFO:
58 return new InfoCommand(System.out);
59 case INIT:
60 return new InitializeCommand(selectedOptions);
61 case BOOTSTRAP:
62 return new BootstrapCommand(selectedOptions);
63 case NEW:
64 return new NewCommand(selectedOptions);
65 case UP:
66 return new UpCommand(selectedOptions);
67 case DOWN:
68 return new DownCommand(selectedOptions);
69 case PENDING:
70 return new PendingCommand(selectedOptions);
71 case SCRIPT:
72 return new ScriptCommand(selectedOptions);
73 case VERSION:
74 return new VersionCommand(selectedOptions);
75 case STATUS:
76 return new StatusCommand(selectedOptions);
77 case REDO:
78 return new RedoCommand(selectedOptions);
79 default:
80 return params -> System.out.println("unknown command");
81 }
82 }
83 }