Skip to content

Commit

Permalink
add version cli command
Browse files Browse the repository at this point in the history
  • Loading branch information
rkm committed Dec 3, 2023
1 parent 0d3f97d commit 058cc24
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 25 deletions.
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@
</descriptorRefs>
<finalName>ctp-anon-cli-${project.version}</finalName>
<appendAssemblyId>false</appendAssemblyId>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
<addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
</manifest>
</archive>
</configuration>
</execution>
</executions>
Expand Down
79 changes: 54 additions & 25 deletions src/main/java/uk/ac/ed/epcc/ctp_anon_cli/Program.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,36 +19,32 @@ public static void main(String[] args) throws ParseException {
Options options = new Options();

Option option = Option
.builder("a")
.argName("file")
.hasArg()
.longOpt("anon-script")
.desc("Anonymisation script")
.required()
.builder("v")
.longOpt("version")
.desc("Print version info and exit")
.build();
options.addOption(option);

option =
Option
.builder("s")
.argName("file")
.hasArg()
.longOpt("sr-anon-tool")
.desc("SR anonymisation tool")
.required()
.build();
options.addOption(option);

option =
Option
.builder("d")
.longOpt("daemonize")
.desc("Run as a daemon and wait for files to process")
.build();
options.addOption(option);

CommandLineParser parser = new DefaultParser();
CommandLine cli = null;

try {
cli = parser.parse(options, args, true);
} catch (ParseException e) {
HelpFormatter formatter = new HelpFormatter();
formatter.printHelp("ctp-anon-cli.jar", AddRequiredOptions(options));
System.exit(1);
}

if (cli.hasOption("v")) {
System.out.println(
"ctp-anon-cli: " + Program.class.getPackage().getImplementationVersion()
);
System.exit(0);
}

options = AddRequiredOptions(options);

try {
cli = parser.parse(options, args);
} catch (ParseException e) {
Expand Down Expand Up @@ -192,6 +188,39 @@ public static void main(String[] args) throws ParseException {
System.exit(rc);
}

private static Options AddRequiredOptions(Options options) {
Option option = Option
.builder("d")
.longOpt("daemonize")
.desc("Run as a daemon and wait for files to process")
.build();
options.addOption(option);

option =
Option
.builder("a")
.argName("file")
.hasArg()
.longOpt("anon-script")
.desc("Anonymisation script")
.required()
.build();
options.addOption(option);

option =
Option
.builder("s")
.argName("file")
.hasArg()
.longOpt("sr-anon-tool")
.desc("SR anonymisation tool")
.required()
.build();
options.addOption(option);

return options;
}

private static File ValidateFilePair(File inFile, File outFile)
throws Exception {
if (outFile.equals(inFile)) {
Expand Down

0 comments on commit 058cc24

Please sign in to comment.