Skip to content

Commit a03550d

Browse files
authored
Merge pull request #607 from brendandburns/exec
Improve the exec example.
2 parents 5ae9164 + 86b1440 commit a03550d

File tree

3 files changed

+26
-9
lines changed

3 files changed

+26
-9
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
language: java
2-
script: mvn -q test -B
2+
script: mvn -q test -B -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn
33
after_success:
4-
- mvn deploy --settings settings.xml -DskipTests=true -B
4+
- mvn deploy --settings settings.xml -DskipTests=true -B -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn

examples/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@
3636
<artifactId>guava</artifactId>
3737
<version>25.1-jre</version>
3838
</dependency>
39+
<dependency>
40+
<groupId>commons-cli</groupId>
41+
<artifactId>commons-cli</artifactId>
42+
<version>1.4</version>
43+
</dependency>
3944
<!-- test dependencies -->
4045
<dependency>
4146
<groupId>junit</groupId>

examples/src/main/java/io/kubernetes/client/examples/ExecExample.java

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@
2121
import java.io.IOException;
2222
import java.util.ArrayList;
2323
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;
2430

2531
/**
2632
* A simple example of how to use the Java API
@@ -31,15 +37,21 @@
3137
* <p>From inside $REPO_DIR/examples
3238
*/
3339
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");
3751
List<String> commands = new ArrayList<>();
3852

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++) {
4355
commands.add(args[i]);
4456
}
4557

0 commit comments

Comments
 (0)