You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+55-8
Original file line number
Diff line number
Diff line change
@@ -1,14 +1,14 @@
1
1
# java-cli-menu
2
-
An clean, interactive command line parser/menu for Java CLI.
2
+
An concise, interactive and versatile command line parser/menu for Java CLI.
3
3
4
-
Idealy, a Java CLI based app can be trigger by ```java -cp <class> <params>```. But sometimes, a menu based configuration is useful and convinient. The interaction looks like:
4
+
Idealy, a Java CLI based app can be trigger by ```java -cp <class> <params>```. But sometimes, a menu based configuration is more useful and convinient. The interaction looks like:
5
5
6
-
```shell 1) --grammar,-g Grammar [Csv] specify grammar name It should be same with file name of your .g4 2) --startRule,-r [token] start rule name. "token" is a special value. -- R): refresh menu; X): exit Your input [# value]: 1 some wrong values >! Bad
6
+
```sh
7
7
Wrong arguments:
8
8
-g: [Invalid_value]
9
9
Only 'Csv' is acceptable!
10
10
1) -g,--grammar []: Grammar name
11
-
2) -,--startRule [token]: Start rule of this parser
11
+
2) -,--startRule [token]: Start rule
12
12
13
13
--
14
14
R): refresh menu; X): exit
@@ -20,7 +20,7 @@ Your input [# value]: 1 Http
20
20
Your input [# value]: 1 Csv
21
21
Your input [# value]: R
22
22
1) -g,--grammar [Csv]: Grammar name
23
-
2) -,--startRule [token]: Start rule of this parser
23
+
2) -,--startRule [token]: Start rule
24
24
25
25
--
26
26
R): refresh menu; X): exit
@@ -32,13 +32,60 @@ Back to main, let's continue.
32
32
33
33
Just try to run
34
34
35
-
- [BeanBuilderSample.java](https://github.com/zhhe-me/java-cli-menu/blob/master/src/test/java/me/zhhe/cli/menu/sample/BeanBuilderSample.java) (extract argument defintion via naming convention or Java Bean)
36
-
- [BasicBuilderSample.java](https://github.com/zhhe-me/java-cli-menu/blob/master/src/test/java/me/zhhe/cli/menu/sample/BasicBuilderSample.java) (set up argument definition via code)
35
+
- [BeanBuilderWithAnnotationSample.java](https://github.com/zhhe-me/java-cli-menu/blob/master/src/test/java/me/zhhe/cli/menu/sample/BeanBuilderWithAnnotationSample.java) (extract argument defintion via annotation + naming convention or Java Bean) **Recommanded**
36
+
- [BeanBuilderSample.java](https://github.com/zhhe-me/java-cli-menu/blob/master/src/test/java/me/zhhe/cli/menu/sample/BeanBuilderSample.java) (extract argument defintion via naming convention or Java Bean) **No configuration**
37
+
- [BasicBuilderSample.java](https://github.com/zhhe-me/java-cli-menu/blob/master/src/test/java/me/zhhe/cli/menu/sample/BasicBuilderSample.java) (set up argument definition via code) **Everything in your control**
37
38
- [ChainedBuilderSample.java](https://github.com/zhhe-me/java-cli-menu/blob/master/src/test/java/me/zhhe/cli/menu/sample/ChainedBuilderSample.java) (set up argument via chained/multiple builders)
38
39
39
40
with input above.
40
41
41
-
This project is on the way and changes will happen any time without notification until it gets GA.
42
+
Here is code from BeanBuilderWithAnnotationSample.java:
43
+
44
+
```java
45
+
public class BeanBuilderWithAnnotationSample {
46
+
47
+
// Annotation can help supply extra info, like arg name, description
48
+
@Option(name = "g", description = "Grammar name")
49
+
private String grammar;
50
+
51
+
// use field name when neither name nor longArgName is specified.
52
+
@Option(description = "Start rule")
53
+
private String startRule;
54
+
55
+
// matched by naming convention
56
+
public void setGrammar(final String value) {
57
+
if (!"Csv".equals(value))
58
+
throw new IllegalArgumentException("Only 'Csv' is acceptable!");
59
+
grammar = value;
60
+
}
61
+
62
+
// ignored due to setStartRule2
63
+
public void setStartRule(final String value) {
64
+
startRule = value;
65
+
}
66
+
67
+
// Annotation is preferred to reflection/naming convention
68
+
@Setter("startRule")
69
+
public void setStartRule2(final String value) {
70
+
startRule = "2-" + value;
71
+
}
72
+
73
+
public static void main(final String... args) {
74
+
final BeanBuilderWithAnnotationSample sample = new BeanBuilderWithAnnotationSample();
75
+
// mock arguments
76
+
final String[] mockedArgs = {"-g", "Invalid_value", "--startRule", "token"};
77
+
78
+
new BeanMenuBuilder().bean(sample).build(mockedArgs).render();
79
+
80
+
// continue your business after all setting is done.
81
+
System.out.println("\nBack to main, let's continue.");
82
+
}
83
+
}
84
+
```
85
+
86
+
87
+
88
+
_This project is on the way and changes will happen any time without notification until it gets GA._
0 commit comments