aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar Ulf Adams <ulfjack@google.com>2015-09-07 09:51:18 +0000
committerGravatar Damien Martin-Guillerez <dmarting@google.com>2015-09-08 09:02:49 +0000
commit895acf58c7fbdcbbb741e6a6641089d4b5feafe5 (patch)
treede3f7dd99efe62389f8229a7ea3964ad70b55f82 /src
parentd0d3505d570336c8c39a48c92ee28e28505edec4 (diff)
Allow canonicalize-flags to run for any command.
-- MOS_MIGRATED_REVID=102483838
Diffstat (limited to 'src')
-rw-r--r--src/main/java/com/google/devtools/build/lib/runtime/commands/CanonicalizeCommand.java32
1 files changed, 8 insertions, 24 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/runtime/commands/CanonicalizeCommand.java b/src/main/java/com/google/devtools/build/lib/runtime/commands/CanonicalizeCommand.java
index 2b7789ee04..82d503ffad 100644
--- a/src/main/java/com/google/devtools/build/lib/runtime/commands/CanonicalizeCommand.java
+++ b/src/main/java/com/google/devtools/build/lib/runtime/commands/CanonicalizeCommand.java
@@ -13,13 +13,13 @@
// limitations under the License.
package com.google.devtools.build.lib.runtime.commands;
+import com.google.common.base.Joiner;
import com.google.devtools.build.lib.events.Event;
import com.google.devtools.build.lib.runtime.BlazeCommand;
import com.google.devtools.build.lib.runtime.BlazeCommandUtils;
import com.google.devtools.build.lib.runtime.BlazeRuntime;
import com.google.devtools.build.lib.runtime.Command;
import com.google.devtools.build.lib.util.ExitCode;
-import com.google.devtools.common.options.Converter;
import com.google.devtools.common.options.Option;
import com.google.devtools.common.options.OptionsBase;
import com.google.devtools.common.options.OptionsParser;
@@ -42,39 +42,23 @@ import java.util.List;
+ "%{options}")
public final class CanonicalizeCommand implements BlazeCommand {
- public static class CommandConverter implements Converter<String> {
-
- @Override
- public String convert(String input) throws OptionsParsingException {
- if (input.equals("build")) {
- return input;
- } else if (input.equals("test")) {
- return input;
- }
- throw new OptionsParsingException("Not a valid command: '" + input + "' (should be "
- + getTypeDescription() + ")");
- }
-
- @Override
- public String getTypeDescription() {
- return "build or test";
- }
- }
-
public static class Options extends OptionsBase {
-
@Option(name = "for_command",
defaultValue = "build",
category = "misc",
- converter = CommandConverter.class,
help = "The command for which the options should be canonicalized.")
public String forCommand;
}
@Override
public ExitCode exec(BlazeRuntime runtime, OptionsProvider options) {
- BlazeCommand command = runtime.getCommandMap().get(
- options.getOptions(Options.class).forCommand);
+ String commandName = options.getOptions(Options.class).forCommand;
+ BlazeCommand command = runtime.getCommandMap().get(commandName);
+ if (command == null) {
+ runtime.getReporter().handle(Event.error("Not a valid command: '" + commandName
+ + "' (should be one of " + Joiner.on(", ").join(runtime.getCommandMap().keySet()) + ")"));
+ return ExitCode.COMMAND_LINE_ERROR;
+ }
Collection<Class<? extends OptionsBase>> optionsClasses =
BlazeCommandUtils.getOptions(
command.getClass(), runtime.getBlazeModules(), runtime.getRuleClassProvider());