Skip to content

Commit 32e9a49

Browse files
mguarnacciasjmillington
authored andcommitted
Bael 3460 (eugenp#8550)
* Hexagonal architecture: a quick and practical example * BAEL 3486 * BAEL-3460 Airline introduction * BAEL-3460 * BAEL-3460 Airline introduction BAEL-3460 * BAEL-3460 * Formatting
1 parent 2a91ba9 commit 32e9a49

File tree

4 files changed

+124
-0
lines changed

4 files changed

+124
-0
lines changed

libraries-3/pom.xml

+6
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@
5858
<artifactId>javase</artifactId>
5959
<version>${qrgen.version}</version>
6060
</dependency>
61+
<dependency>
62+
<groupId>com.github.rvesse</groupId>
63+
<artifactId>airline</artifactId>
64+
<version>${airline.version}</version>
65+
</dependency>
6166
<dependency>
6267
<groupId>org.cactoos</groupId>
6368
<artifactId>cactoos</artifactId>
@@ -82,5 +87,6 @@
8287
<qrgen.version>2.6.0</qrgen.version>
8388

8489
<cactoos.version>0.43</cactoos.version>
90+
<airline.version>2.7.2</airline.version>
8591
</properties>
8692
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.baeldung.airline;
2+
3+
import com.github.rvesse.airline.annotations.Cli;
4+
import com.github.rvesse.airline.help.Help;
5+
6+
@Cli(name = "baeldung-cli",
7+
description = "Baeldung Airline Tutorial",
8+
defaultCommand = Help.class,
9+
commands = { DatabaseSetupCommand.class, LoggingCommand.class, Help.class })
10+
public class CommandLine {
11+
12+
public static void main(String[] args) {
13+
com.github.rvesse.airline.Cli<Runnable> cli = new com.github.rvesse.airline.Cli<>(CommandLine.class);
14+
Runnable cmd = cli.parse(args);
15+
cmd.run();
16+
}
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
package com.baeldung.airline;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
import javax.inject.Inject;
7+
8+
import com.github.rvesse.airline.HelpOption;
9+
import com.github.rvesse.airline.annotations.Command;
10+
import com.github.rvesse.airline.annotations.Option;
11+
import com.github.rvesse.airline.annotations.OptionType;
12+
import com.github.rvesse.airline.annotations.restrictions.AllowedRawValues;
13+
import com.github.rvesse.airline.annotations.restrictions.MutuallyExclusiveWith;
14+
import com.github.rvesse.airline.annotations.restrictions.Pattern;
15+
import com.github.rvesse.airline.annotations.restrictions.RequiredOnlyIf;
16+
17+
@Command(name = "setup-db", description = "Setup our database")
18+
public class DatabaseSetupCommand implements Runnable {
19+
@Inject
20+
private HelpOption<DatabaseSetupCommand> help;
21+
22+
@Option(type = OptionType.COMMAND,
23+
name = {"-d", "--database"},
24+
description = "Type of RDBMS.",
25+
title = "RDBMS type: mysql|postgresql|mongodb")
26+
@AllowedRawValues(allowedValues = { "mysql", "postgres", "mongodb" })
27+
protected String rdbmsMode = "mysql";
28+
29+
@Option(type = OptionType.COMMAND,
30+
name = {"--rdbms:url", "--url"},
31+
description = "URL to use for connection to RDBMS.",
32+
title = "RDBMS URL")
33+
@MutuallyExclusiveWith(tag="mode")
34+
@Pattern(pattern="^(http://.*):(d*)(.*)u=(.*)&p=(.*)")
35+
protected String rdbmsUrl = "";
36+
37+
@Option(type = OptionType.COMMAND,
38+
name = {"--rdbms:host", "--host"},
39+
description = "Host to use for connection to RDBMS.",
40+
title = "RDBMS host")
41+
@MutuallyExclusiveWith(tag="mode")
42+
protected String rdbmsHost = "";
43+
44+
@RequiredOnlyIf(names={"--rdbms:host", "--host"})
45+
@Option(type = OptionType.COMMAND,
46+
name = {"--rdbms:user", "-u", "--user"},
47+
description = "User for login to RDBMS.",
48+
title = "RDBMS user")
49+
protected String rdbmsUser;
50+
51+
@RequiredOnlyIf(names={"--rdbms:host", "--host"})
52+
@Option(type = OptionType.COMMAND,
53+
name = {"--rdbms:password", "--password"},
54+
description = "Password for login to RDBMS.",
55+
title = "RDBMS password")
56+
protected String rdbmsPassword;
57+
58+
@Option(type = OptionType.COMMAND,
59+
name = {"--driver", "--jars"},
60+
description = "List of drivers",
61+
title = "--driver <PATH_TO_YOUR_JAR> --driver <PATH_TO_YOUR_JAR>")
62+
protected List<String> jars = new ArrayList<>();
63+
64+
@Override
65+
public void run() {
66+
//skipping store our choices...
67+
if (!help.showHelpIfRequested()) {
68+
if(!"".equals(rdbmsHost)) {
69+
System.out.println("Connecting to database host: " + rdbmsHost);
70+
System.out.println("Credential: " + rdbmsUser + " / " + rdbmsPassword);
71+
} else {
72+
System.out.println("Connecting to database url: " + rdbmsUrl);
73+
}
74+
System.out.println(jars.toString());
75+
}
76+
}
77+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.baeldung.airline;
2+
3+
import javax.inject.Inject;
4+
5+
import com.github.rvesse.airline.HelpOption;
6+
import com.github.rvesse.airline.annotations.Command;
7+
import com.github.rvesse.airline.annotations.Option;
8+
9+
@Command(name = "setup-log", description = "Setup our log")
10+
public class LoggingCommand implements Runnable {
11+
12+
@Inject
13+
private HelpOption<LoggingCommand> help;
14+
15+
@Option(name = { "-v", "--verbose" }, description = "Set log verbosity on/off")
16+
private boolean verbose = false;
17+
18+
@Override
19+
public void run() {
20+
//skipping store user choice
21+
if (!help.showHelpIfRequested())
22+
System.out.println("Verbosity: " + verbose);
23+
}
24+
}

0 commit comments

Comments
 (0)