Skip to content

Commit

Permalink
INFRA-541 Parse Cuppa arguments properly
Browse files Browse the repository at this point in the history
Pull out only those arguments that are for each application based on
whether they have a prefix or not, then pass the appropriate ones to
each application in turn.
  • Loading branch information
Ned Leitch committed Sep 6, 2024
1 parent 26f4032 commit 2d5127f
Showing 1 changed file with 29 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,41 @@
package com.hartwig.hmftools.cup.cli;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

import com.hartwig.hmftools.cup.prep.CuppaDataPrep;

public class PrepPlusPredictionMain {
private static String[] extract(String prefix, String[] allArgs) {
List<String> allAsString = Arrays.stream(allArgs).collect(Collectors.toList());
List<String> matchingArgs = new ArrayList<>();
List<String> accumulator = new ArrayList<>();
String argPrefix = String.format("-%s_", prefix);
for (String arg: allAsString) {
if (arg.startsWith(argPrefix)) {
matchingArgs.addAll(accumulator);
accumulator.clear();
accumulator.add("-" + arg.substring(argPrefix.length()));
}
else {
if (!(arg.startsWith("-") || accumulator.isEmpty())) {
accumulator.add(arg);
}
}
}
matchingArgs.addAll(accumulator);
return matchingArgs.toArray(new String[] {});
}

public static void main(String[] args) {
try {
CuppaDataPrep.main(args);
PredictionRunner.main(args);
CuppaDataPrep.main(extract("prep", args));
PredictionRunner.main(extract("prediction", args));
System.exit(0);
} catch (Exception e) {
System.err.println("Failed to run combined Cuppa applications");
e.printStackTrace();
System.exit(1);
}
Expand Down

0 comments on commit 2d5127f

Please sign in to comment.