diff --git a/helios-tools/src/main/java/com/spotify/helios/cli/command/JobCreateCommand.java b/helios-tools/src/main/java/com/spotify/helios/cli/command/JobCreateCommand.java index fd2b4458a..68a7821d4 100644 --- a/helios-tools/src/main/java/com/spotify/helios/cli/command/JobCreateCommand.java +++ b/helios-tools/src/main/java/com/spotify/helios/cli/command/JobCreateCommand.java @@ -107,7 +107,6 @@ public JobCreateCommand(final Subparser parser) { envArg = parser.addArgument("--env") .action(append()) .setDefault(new ArrayList()) - .nargs("+") .help("Environment variables"); portArg = parser.addArgument("-p", "--port") @@ -125,7 +124,6 @@ public JobCreateCommand(final Subparser parser) { registrationArg = parser.addArgument("-r", "--register") .action(append()) .setDefault(new ArrayList()) - .nargs("+") .help("Service discovery registration. Specify a service name, the port name and a " + "protocol on the format service/protocol=port. E.g. -r website/tcp=http will " + "register the port named http with the protocol tcp. Protocol is optional and " + @@ -232,18 +230,16 @@ int run(Namespace options, HeliosClient client, PrintStream out, final boolean j builder.setCommand(command); } - final List> envList = options.getList(envArg.getDest()); + final List envList = options.getList(envArg.getDest()); if (!envList.isEmpty()) { final ImmutableMap.Builder env = ImmutableMap.builder(); env.putAll(builder.getEnv()); - for (final List group : envList) { - for (final String s : group) { - final String[] parts = s.split("=", 2); - if (parts.length != 2) { - throw new IllegalArgumentException("Bad environment variable: " + s); - } - env.put(parts[0], parts[1]); + for (final String s : envList) { + final String[] parts = s.split("=", 2); + if (parts.length != 2) { + throw new IllegalArgumentException("Bad environment variable: " + s); } + env.put(parts[0], parts[1]); } builder.setEnv(env.build()); } @@ -280,35 +276,33 @@ int run(Namespace options, HeliosClient client, PrintStream out, final boolean j final Map explicitRegistration = Maps.newHashMap(); final Pattern registrationPattern = compile("(?[a-zA-Z][_\\-\\w]+)(?:/(?\\w+))?(?:=(?[_\\-\\w]+))?"); - final List> registrationSpecLists = options.getList(registrationArg.getDest()); - for (List registrationSpecList : registrationSpecLists) { - for (final String spec : registrationSpecList) { - final Matcher matcher = registrationPattern.matcher(spec); - if (!matcher.matches()) { - throw new IllegalArgumentException("Bad registration: " + spec); - } + final List registrationSpecs = options.getList(registrationArg.getDest()); + for (final String spec : registrationSpecs) { + final Matcher matcher = registrationPattern.matcher(spec); + if (!matcher.matches()) { + throw new IllegalArgumentException("Bad registration: " + spec); + } - final String service = matcher.group("srv"); - final String proto = fromNullable(matcher.group("prot")).or(HTTP); - final String optionalPort = matcher.group("port"); - final String port; + final String service = matcher.group("srv"); + final String proto = fromNullable(matcher.group("prot")).or(HTTP); + final String optionalPort = matcher.group("port"); + final String port; - if (ports.size() == 0) { - throw new IllegalArgumentException("Need port mappings for service registration."); - } + if (ports.size() == 0) { + throw new IllegalArgumentException("Need port mappings for service registration."); + } - if (optionalPort == null) { - if (ports.size() != 1) { - throw new IllegalArgumentException( - "Need exactly one port mapping for implicit service registration"); - } - port = Iterables.getLast(ports.keySet()); - } else { - port = optionalPort; + if (optionalPort == null) { + if (ports.size() != 1) { + throw new IllegalArgumentException( + "Need exactly one port mapping for implicit service registration"); } - - explicitRegistration.put(ServiceEndpoint.of(service, proto), ServicePorts.of(port)); + port = Iterables.getLast(ports.keySet()); + } else { + port = optionalPort; } + + explicitRegistration.put(ServiceEndpoint.of(service, proto), ServicePorts.of(port)); } // Merge service registrations