Skip to content

Commit 058cc24

Browse files
committed
add version cli command
1 parent 0d3f97d commit 058cc24

File tree

2 files changed

+60
-25
lines changed

2 files changed

+60
-25
lines changed

pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@
5959
</descriptorRefs>
6060
<finalName>ctp-anon-cli-${project.version}</finalName>
6161
<appendAssemblyId>false</appendAssemblyId>
62+
<archive>
63+
<manifest>
64+
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
65+
<addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
66+
</manifest>
67+
</archive>
6268
</configuration>
6369
</execution>
6470
</executions>

src/main/java/uk/ac/ed/epcc/ctp_anon_cli/Program.java

Lines changed: 54 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -19,36 +19,32 @@ public static void main(String[] args) throws ParseException {
1919
Options options = new Options();
2020

2121
Option option = Option
22-
.builder("a")
23-
.argName("file")
24-
.hasArg()
25-
.longOpt("anon-script")
26-
.desc("Anonymisation script")
27-
.required()
22+
.builder("v")
23+
.longOpt("version")
24+
.desc("Print version info and exit")
2825
.build();
2926
options.addOption(option);
3027

31-
option =
32-
Option
33-
.builder("s")
34-
.argName("file")
35-
.hasArg()
36-
.longOpt("sr-anon-tool")
37-
.desc("SR anonymisation tool")
38-
.required()
39-
.build();
40-
options.addOption(option);
41-
42-
option =
43-
Option
44-
.builder("d")
45-
.longOpt("daemonize")
46-
.desc("Run as a daemon and wait for files to process")
47-
.build();
48-
options.addOption(option);
49-
5028
CommandLineParser parser = new DefaultParser();
5129
CommandLine cli = null;
30+
31+
try {
32+
cli = parser.parse(options, args, true);
33+
} catch (ParseException e) {
34+
HelpFormatter formatter = new HelpFormatter();
35+
formatter.printHelp("ctp-anon-cli.jar", AddRequiredOptions(options));
36+
System.exit(1);
37+
}
38+
39+
if (cli.hasOption("v")) {
40+
System.out.println(
41+
"ctp-anon-cli: " + Program.class.getPackage().getImplementationVersion()
42+
);
43+
System.exit(0);
44+
}
45+
46+
options = AddRequiredOptions(options);
47+
5248
try {
5349
cli = parser.parse(options, args);
5450
} catch (ParseException e) {
@@ -192,6 +188,39 @@ public static void main(String[] args) throws ParseException {
192188
System.exit(rc);
193189
}
194190

191+
private static Options AddRequiredOptions(Options options) {
192+
Option option = Option
193+
.builder("d")
194+
.longOpt("daemonize")
195+
.desc("Run as a daemon and wait for files to process")
196+
.build();
197+
options.addOption(option);
198+
199+
option =
200+
Option
201+
.builder("a")
202+
.argName("file")
203+
.hasArg()
204+
.longOpt("anon-script")
205+
.desc("Anonymisation script")
206+
.required()
207+
.build();
208+
options.addOption(option);
209+
210+
option =
211+
Option
212+
.builder("s")
213+
.argName("file")
214+
.hasArg()
215+
.longOpt("sr-anon-tool")
216+
.desc("SR anonymisation tool")
217+
.required()
218+
.build();
219+
options.addOption(option);
220+
221+
return options;
222+
}
223+
195224
private static File ValidateFilePair(File inFile, File outFile)
196225
throws Exception {
197226
if (outFile.equals(inFile)) {

0 commit comments

Comments
 (0)