Skip to content

Commit 9e48f04

Browse files
committed
Dodanie podstawowej opcji CL pomocy (-h)
1 parent 72a6481 commit 9e48f04

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@
4444
<artifactId>gson</artifactId>
4545
<version>2.11.0</version>
4646
</dependency>
47+
<dependency>
48+
<groupId>commons-cli</groupId>
49+
<artifactId>commons-cli</artifactId>
50+
<version>1.9.0</version>
51+
</dependency>
4752
</dependencies>
4853

4954
<licenses>

src/main/java/pl/koder95/cmf/Main.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package pl.koder95.cmf;
22

3+
import org.apache.commons.cli.*;
4+
35
import java.util.Arrays;
46

57
public class Main {
@@ -8,5 +10,18 @@ public static void main(String[] args) {
810
System.out.println("Catholic Moveable Feasts by Kamil Jan Mularski [Koder95]. See more: https://koder95.pl/");
911
System.out.println("— It is starting with arguments: " + Arrays.deepToString(args));
1012
System.out.println();
13+
14+
Options options = new Options();
15+
options.addOption("h", "help", false, "wyświetla pomoc programu");
16+
CommandLineParser parser = new DefaultParser(false);
17+
try {
18+
CommandLine cl = parser.parse(options, args);
19+
if (cl.hasOption("h")) {
20+
HelpFormatter hf = new HelpFormatter();
21+
hf.printHelp("cmf", options);
22+
}
23+
} catch (ParseException e) {
24+
throw new RuntimeException(e);
25+
}
1126
}
1227
}

0 commit comments

Comments
 (0)