|
1 | 1 | package com.redislabs.riot;
|
2 | 2 |
|
3 |
| -import java.net.InetAddress; |
4 | 3 | import java.util.List;
|
5 | 4 | import java.util.Locale;
|
6 | 5 |
|
7 | 6 | import org.springframework.boot.CommandLineRunner;
|
8 | 7 | import org.springframework.boot.SpringApplication;
|
9 | 8 | import org.springframework.boot.autoconfigure.SpringBootApplication;
|
10 | 9 |
|
11 |
| -import com.redislabs.riot.cli.Export; |
12 |
| -import com.redislabs.riot.cli.Import; |
13 |
| -import com.redislabs.riot.redis.RedisConnectionBuilder; |
| 10 | +import com.redislabs.riot.cli.RootCommand; |
14 | 11 |
|
15 |
| -import io.lettuce.core.RedisURI; |
16 |
| -import lombok.Getter; |
17 | 12 | import picocli.CommandLine;
|
18 |
| -import picocli.CommandLine.Command; |
19 | 13 | import picocli.CommandLine.DefaultExceptionHandler;
|
20 |
| -import picocli.CommandLine.Option; |
21 | 14 | import picocli.CommandLine.RunLast;
|
22 |
| -import redis.clients.jedis.Protocol; |
23 | 15 |
|
24 | 16 | @SpringBootApplication
|
25 |
| -@Command(name = "riot", subcommands = { Export.class, Import.class }) |
26 |
| -public class RiotApplication extends BaseCommand implements CommandLineRunner { |
| 17 | +public class RiotApplication implements CommandLineRunner { |
| 18 | + |
| 19 | + private RootCommand riot = new RootCommand(); |
27 | 20 |
|
28 | 21 | public static void main(String[] args) {
|
29 | 22 | SpringApplication.run(RiotApplication.class, args);
|
30 | 23 | }
|
31 | 24 |
|
32 |
| - public static final String DEFAULT_HOST = "localhost"; |
33 |
| - |
34 |
| - public enum RedisDriver { |
35 |
| - Jedis, Lettuce |
36 |
| - } |
37 |
| - |
38 |
| - /** |
39 |
| - * Just to avoid picocli complain in Eclipse console |
40 |
| - */ |
41 |
| - @Option(names = "--spring.output.ansi.enabled", hidden = true) |
42 |
| - private String ansiEnabled; |
43 |
| - |
44 |
| - @Option(names = "--driver", description = "Redis driver: ${COMPLETION-CANDIDATES}. (default: ${DEFAULT-VALUE})") |
45 |
| - @Getter |
46 |
| - private RedisDriver driver = RedisDriver.Jedis; |
47 |
| - @Option(names = "--host", description = "Redis server host. (default: localhost).") |
48 |
| - private InetAddress host; |
49 |
| - @Option(names = "--port", description = "Redis server port. (default: ${DEFAULT-VALUE}).") |
50 |
| - private int port = RedisURI.DEFAULT_REDIS_PORT; |
51 |
| - @Option(names = "--command-timeout", description = "Redis command timeout in seconds for synchronous command execution (default: ${DEFAULT-VALUE}).") |
52 |
| - private long commandTimeout = RedisURI.DEFAULT_TIMEOUT; |
53 |
| - @Option(names = "--connection-timeout", description = "Redis connect timeout in milliseconds. (default: ${DEFAULT-VALUE}).") |
54 |
| - private int connectionTimeout = Protocol.DEFAULT_TIMEOUT; |
55 |
| - @Option(names = "--socket-timeout", description = "Redis socket timeout in milliseconds. (default: ${DEFAULT-VALUE}).") |
56 |
| - private int socketTimeout = Protocol.DEFAULT_TIMEOUT; |
57 |
| - @Option(names = "--password", description = "Redis database password.", interactive = true) |
58 |
| - private String password; |
59 |
| - @Option(names = "--max-idle", description = "Maximum number of idle connections in the pool. Use a negative value to indicate an unlimited number of idle connections. (default: ${DEFAULT-VALUE}).") |
60 |
| - private int maxIdle = 8; |
61 |
| - @Option(names = "--min-idle", description = "Target for the minimum number of idle connections to maintain in the pool. This setting only has an effect if it is positive. (default: ${DEFAULT-VALUE}).") |
62 |
| - private int minIdle = 0; |
63 |
| - @Option(names = "--max-total", description = "Maximum number of connections that can be allocated by the pool at a given time. Use a negative value for no limit. (default: ${DEFAULT-VALUE})") |
64 |
| - private int maxTotal = 8; |
65 |
| - @Option(names = "--max-wait", description = "Maximum amount of time in milliseconds a connection allocation should block before throwing an exception when the pool is exhausted. Use a negative value to block indefinitely (default).") |
66 |
| - private long maxWait = -1L; |
67 |
| - @Option(names = "--database", description = "Redis database number. Databases are only available for Redis Standalone and Redis Master/Slave. (default: ${DEFAULT-VALUE}).") |
68 |
| - private int database = 0; |
69 |
| - @Option(names = "--client-name", description = "Redis client name.") |
70 |
| - private String clientName; |
71 |
| - |
72 |
| - public RedisConnectionBuilder redisConnectionBuilder() { |
73 |
| - RedisConnectionBuilder builder = new RedisConnectionBuilder(); |
74 |
| - builder.setClientName(clientName); |
75 |
| - builder.setCommandTimeout(commandTimeout); |
76 |
| - builder.setConnectionTimeout(connectionTimeout); |
77 |
| - builder.setDatabase(database); |
78 |
| - builder.setHost(getHostname()); |
79 |
| - builder.setMaxTotal(maxTotal); |
80 |
| - builder.setMaxIdle(maxIdle); |
81 |
| - builder.setMaxWait(maxWait); |
82 |
| - builder.setMinIdle(minIdle); |
83 |
| - builder.setPassword(password); |
84 |
| - builder.setPort(port); |
85 |
| - builder.setSocketTimeout(socketTimeout); |
86 |
| - return builder; |
87 |
| - } |
88 |
| - |
89 |
| - private String getHostname() { |
90 |
| - if (host != null) { |
91 |
| - return host.getHostName(); |
92 |
| - } |
93 |
| - return DEFAULT_HOST; |
94 |
| - } |
95 |
| - |
96 | 25 | @Override
|
97 | 26 | public void run(String... args) {
|
98 |
| - CommandLine commandLine = new CommandLine(this); |
| 27 | + CommandLine commandLine = new CommandLine(riot); |
99 | 28 | commandLine.registerConverter(Locale.class, s -> new Locale.Builder().setLanguageTag(s).build());
|
100 | 29 | commandLine.setCaseInsensitiveEnumValuesAllowed(true);
|
101 | 30 | RunLast handler = new RunLast();
|
|
0 commit comments