Skip to content

Commit 1994f86

Browse files
committed
add CommandLineParserTest
1 parent cc51aac commit 1994f86

2 files changed

Lines changed: 42 additions & 0 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
# java_study
22
java study
3+
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import org.apache.commons.cli.*;
2+
3+
public class CommandLineParserTest {
4+
public static void main(String[] args) throws ParseException {
5+
Options options = new Options();
6+
7+
options.addOption(Option.builder().longOpt("host")
8+
.desc("smtp server host")
9+
.hasArg()
10+
.build());
11+
12+
options.addOption(Option.builder().longOpt("port")
13+
.desc("smtp server port")
14+
.hasArg()
15+
.build());
16+
17+
options.addOption(Option.builder().longOpt("from")
18+
.desc("from address")
19+
.hasArg()
20+
.build());
21+
22+
options.addOption(Option.builder().longOpt("to")
23+
.desc("to address")
24+
.hasArg()
25+
.build());
26+
27+
CommandLineParser parser = new DefaultParser();
28+
29+
CommandLine line = parser.parse(options, args);
30+
31+
String host = line.getOptionValue("host");
32+
String port = line.getOptionValue("port");
33+
String from = line.getOptionValue("from");
34+
String to = line.getOptionValue("to");
35+
36+
System.out.println(host);
37+
System.out.println(port);
38+
System.out.println(from);
39+
System.out.println(to);
40+
}
41+
}

0 commit comments

Comments
 (0)