|
21 | 21 | import java.io.IOException;
|
22 | 22 | import java.util.ArrayList;
|
23 | 23 | import java.util.List;
|
| 24 | +import org.apache.commons.cli.CommandLine; |
| 25 | +import org.apache.commons.cli.CommandLineParser; |
| 26 | +import org.apache.commons.cli.DefaultParser; |
| 27 | +import org.apache.commons.cli.Option; |
| 28 | +import org.apache.commons.cli.Options; |
| 29 | +import org.apache.commons.cli.ParseException; |
24 | 30 |
|
25 | 31 | /**
|
26 | 32 | * A simple example of how to use the Java API
|
|
31 | 37 | * <p>From inside $REPO_DIR/examples
|
32 | 38 | */
|
33 | 39 | public class ExecExample {
|
34 |
| - public static void main(String[] args) throws IOException, ApiException, InterruptedException { |
35 |
| - String podName = "nginx-4217019353-k5sn9"; |
36 |
| - String namespace = "default"; |
| 40 | + public static void main(String[] args) |
| 41 | + throws IOException, ApiException, InterruptedException, ParseException { |
| 42 | + final Options options = new Options(); |
| 43 | + options.addOption(new Option("p", "pod", true, "The name of the pod")); |
| 44 | + options.addOption(new Option("n", "namespace", true, "The namespace of the pod")); |
| 45 | + |
| 46 | + CommandLineParser parser = new DefaultParser(); |
| 47 | + CommandLine cmd = parser.parse(options, args); |
| 48 | + |
| 49 | + String podName = cmd.getOptionValue("p", "nginx-dbddb74b8-s4cx5"); |
| 50 | + String namespace = cmd.getOptionValue("n", "default"); |
37 | 51 | List<String> commands = new ArrayList<>();
|
38 | 52 |
|
39 |
| - int len = args.length; |
40 |
| - if (len >= 1) podName = args[0]; |
41 |
| - if (len >= 2) namespace = args[1]; |
42 |
| - for (int i = 2; i < len; i++) { |
| 53 | + args = cmd.getArgs(); |
| 54 | + for (int i = 0; i < args.length; i++) { |
43 | 55 | commands.add(args[i]);
|
44 | 56 | }
|
45 | 57 |
|
|
0 commit comments