From 895acf58c7fbdcbbb741e6a6641089d4b5feafe5 Mon Sep 17 00:00:00 2001 From: Ulf Adams Date: Mon, 7 Sep 2015 09:51:18 +0000 Subject: Allow canonicalize-flags to run for any command. -- MOS_MIGRATED_REVID=102483838 --- .../lib/runtime/commands/CanonicalizeCommand.java | 32 ++++++---------------- 1 file changed, 8 insertions(+), 24 deletions(-) (limited to 'src') 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 { - - @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> optionsClasses = BlazeCommandUtils.getOptions( command.getClass(), runtime.getBlazeModules(), runtime.getRuleClassProvider()); -- cgit v1.2.3