Search in sources :

Example 1 with Command

use of com.google.devtools.build.lib.runtime.Command in project bazel by bazelbuild.

the class HelpCommand method emitCompletionHelp.

private void emitCompletionHelp(BlazeRuntime runtime, OutErr outErr) {
    // First startup_options
    Iterable<BlazeModule> blazeModules = runtime.getBlazeModules();
    ConfiguredRuleClassProvider ruleClassProvider = runtime.getRuleClassProvider();
    Map<String, BlazeCommand> commandsByName = getSortedCommands(runtime);
    outErr.printOutLn("BAZEL_COMMAND_LIST=\"" + SPACE_JOINER.join(commandsByName.keySet()) + "\"");
    outErr.printOutLn("BAZEL_INFO_KEYS=\"");
    for (String name : InfoCommand.getHardwiredInfoItemNames(runtime.getProductName())) {
        outErr.printOutLn(name);
    }
    outErr.printOutLn("\"");
    outErr.printOutLn("BAZEL_STARTUP_OPTIONS=\"");
    Iterable<Class<? extends OptionsBase>> options = BlazeCommandUtils.getStartupOptions(blazeModules);
    outErr.printOut(OptionsParser.newOptionsParser(options).getOptionsCompletion());
    outErr.printOutLn("\"");
    for (Map.Entry<String, BlazeCommand> e : commandsByName.entrySet()) {
        BlazeCommand command = e.getValue();
        String varName = e.getKey().toUpperCase(Locale.US).replace('-', '_');
        Command annotation = command.getClass().getAnnotation(Command.class);
        if (!annotation.completion().isEmpty()) {
            outErr.printOutLn("BAZEL_COMMAND_" + varName + "_ARGUMENT=\"" + annotation.completion() + "\"");
        }
        options = BlazeCommandUtils.getOptions(command.getClass(), blazeModules, ruleClassProvider);
        outErr.printOutLn("BAZEL_COMMAND_" + varName + "_FLAGS=\"");
        outErr.printOut(OptionsParser.newOptionsParser(options).getOptionsCompletion());
        outErr.printOutLn("\"");
    }
}
Also used : OptionsBase(com.google.devtools.common.options.OptionsBase) BlazeCommand(com.google.devtools.build.lib.runtime.BlazeCommand) ConfiguredRuleClassProvider(com.google.devtools.build.lib.analysis.ConfiguredRuleClassProvider) BlazeCommand(com.google.devtools.build.lib.runtime.BlazeCommand) Command(com.google.devtools.build.lib.runtime.Command) RuleClass(com.google.devtools.build.lib.packages.RuleClass) BlazeModule(com.google.devtools.build.lib.runtime.BlazeModule) Map(java.util.Map) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 2 with Command

use of com.google.devtools.build.lib.runtime.Command in project bazel by bazelbuild.

the class HelpCommand method emitGenericHelp.

private void emitGenericHelp(OutErr outErr, BlazeRuntime runtime) {
    outErr.printOut(String.format("Usage: %s <command> <options> ...\n\n", runtime.getProductName()));
    outErr.printOut("Available commands:\n");
    Map<String, BlazeCommand> commandsByName = runtime.getCommandMap();
    List<String> namesInOrder = new ArrayList<>(commandsByName.keySet());
    Collections.sort(namesInOrder);
    for (String name : namesInOrder) {
        BlazeCommand command = commandsByName.get(name);
        Command annotation = command.getClass().getAnnotation(Command.class);
        if (annotation.hidden()) {
            continue;
        }
        String shortDescription = annotation.shortDescription().replace("%{product}", runtime.getProductName());
        outErr.printOut(String.format("  %-19s %s\n", name, shortDescription));
    }
    outErr.printOut("\n");
    outErr.printOut("Getting more help:\n");
    outErr.printOut(String.format("  %s help <command>\n", runtime.getProductName()));
    outErr.printOut("                   Prints help and options for <command>.\n");
    outErr.printOut(String.format("  %s help startup_options\n", runtime.getProductName()));
    outErr.printOut(String.format("                   Options for the JVM hosting %s.\n", runtime.getProductName()));
    outErr.printOut(String.format("  %s help target-syntax\n", runtime.getProductName()));
    outErr.printOut("                   Explains the syntax for specifying targets.\n");
    outErr.printOut(String.format("  %s help info-keys\n", runtime.getProductName()));
    outErr.printOut("                   Displays a list of keys used by the info command.\n");
}
Also used : BlazeCommand(com.google.devtools.build.lib.runtime.BlazeCommand) BlazeCommand(com.google.devtools.build.lib.runtime.BlazeCommand) Command(com.google.devtools.build.lib.runtime.Command) ArrayList(java.util.ArrayList)

Aggregations

BlazeCommand (com.google.devtools.build.lib.runtime.BlazeCommand)2 Command (com.google.devtools.build.lib.runtime.Command)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSortedMap (com.google.common.collect.ImmutableSortedMap)1 ConfiguredRuleClassProvider (com.google.devtools.build.lib.analysis.ConfiguredRuleClassProvider)1 RuleClass (com.google.devtools.build.lib.packages.RuleClass)1 BlazeModule (com.google.devtools.build.lib.runtime.BlazeModule)1 OptionsBase (com.google.devtools.common.options.OptionsBase)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1