|
9 | 9 | import java.io.PrintStream; |
10 | 10 | import java.io.FileOutputStream; |
11 | 11 | import java.nio.file.Files; |
| 12 | +import java.nio.file.Path; |
12 | 13 | import java.nio.file.Paths; |
13 | 14 | import java.util.ArrayList; |
14 | 15 | import java.util.Arrays; |
15 | 16 | import java.util.List; |
16 | 17 | import java.util.function.Consumer; |
| 18 | +import java.util.stream.Stream; |
17 | 19 |
|
18 | 20 | import joptsimple.OptionException; |
19 | 21 | import joptsimple.OptionParser; |
|
28 | 30 |
|
29 | 31 | public class Main { |
30 | 32 | public static void main(String[] args) throws IOException { |
| 33 | + List<String> params = new ArrayList<>(); |
| 34 | + for (int x = 0; x < args.length; x++) { |
| 35 | + if (args[x].startsWith("--cfg")) { |
| 36 | + String path = null; |
| 37 | + if (args[x].startsWith("--cfg=")) { |
| 38 | + path = args[x].substring(6); |
| 39 | + } else if (args.length > x + 1) { |
| 40 | + path = args[++x]; |
| 41 | + } else { |
| 42 | + System.out.println("Must specify a file when using --cfg argument."); |
| 43 | + return; |
| 44 | + } |
| 45 | + |
| 46 | + Path file = Paths.get(path); |
| 47 | + if (!Files.exists(file)) { |
| 48 | + System.out.println("error: missing config '" + path + "'"); |
| 49 | + return; |
| 50 | + } |
| 51 | + try (Stream<String> stream = Files.lines(file)) { |
| 52 | + stream.forEach(params::add); |
| 53 | + } catch (IOException e) { |
| 54 | + System.out.println("error: Failed to read config file '" + path + "'"); |
| 55 | + throw new RuntimeException(e); |
| 56 | + } |
| 57 | + } else { |
| 58 | + params.add(args[x]); |
| 59 | + } |
| 60 | + } |
| 61 | + args = params.toArray(new String[params.size()]); |
| 62 | + |
31 | 63 | OptionParser parser = new OptionParser(); |
32 | 64 | OptionSpec<File> inputO = parser.accepts("input", "Input jar file").withRequiredArg().ofType(File.class).required(); |
33 | 65 | OptionSpec<File> outputO = parser.accepts("output", "Output jar file, if unspecifed, overwrites input").withRequiredArg().ofType(File.class); |
|
0 commit comments