@@ -19,36 +19,32 @@ public static void main(String[] args) throws ParseException {
19
19
Options options = new Options ();
20
20
21
21
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" )
28
25
.build ();
29
26
options .addOption (option );
30
27
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
-
50
28
CommandLineParser parser = new DefaultParser ();
51
29
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
+
52
48
try {
53
49
cli = parser .parse (options , args );
54
50
} catch (ParseException e ) {
@@ -192,6 +188,39 @@ public static void main(String[] args) throws ParseException {
192
188
System .exit (rc );
193
189
}
194
190
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
+
195
224
private static File ValidateFilePair (File inFile , File outFile )
196
225
throws Exception {
197
226
if (outFile .equals (inFile )) {
0 commit comments