blob: 4db562790cc93bf872d71754cbe96c782caffd8c [file] [log] [blame]
Damien Martin-Guillerezf88f4d82015-09-25 13:56:55 +00001// Copyright 2014 The Bazel Authors. All rights reserved.
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +01002//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14package com.google.devtools.build.lib.runtime;
15
16import com.google.devtools.common.options.Option;
17import com.google.devtools.common.options.OptionsBase;
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010018import java.lang.annotation.ElementType;
19import java.lang.annotation.Retention;
20import java.lang.annotation.RetentionPolicy;
21import java.lang.annotation.Target;
22
23/**
24 * An annotation that lets blaze commands specify their options and their help.
25 * The annotations are processed by {@link BlazeCommand}.
26 */
27@Target(ElementType.TYPE)
28@Retention(RetentionPolicy.RUNTIME)
29public @interface Command {
30 /**
31 * The name of the command, as the user would type it.
32 */
33 String name();
34
35 /**
36 * Options processed by the command, indicated by options interfaces.
37 * These interfaces must contain methods annotated with {@link Option}.
38 */
39 Class<? extends OptionsBase>[] options() default {};
40
41 /**
42 * The set of other Blaze commands that this annotation's command "inherits"
43 * options from. These classes must be annotated with {@link Command}.
44 */
45 Class<? extends BlazeCommand>[] inherits() default {};
46
47 /**
48 * A short description, which appears in 'blaze help'.
49 */
50 String shortDescription();
51
52 /**
53 * True if the configuration-specific options should be available for this command.
54 */
55 boolean usesConfigurationOptions() default false;
56
57 /**
58 * True if the command runs a build.
59 */
60 boolean builds() default false;
61
62 /**
63 * True if the command should not be shown in the output of 'blaze help'.
64 */
65 boolean hidden() default false;
66
67 /**
68 * Specifies whether this command allows a residue after the parsed options.
69 * For example, a command might expect a list of targets to build in the
70 * residue.
71 */
72 boolean allowResidue() default false;
73
74 /**
75 * Returns true if this command wants to write binary data to stdout.
76 * Enabling this flag will disable ANSI escape stripping for this command.
Shreya Bhattaraicd03ca22015-08-03 20:33:30 +000077 * This should be used in conjunction with {@code Reporter#switchToAnsiAllowingHandler}.
78 * See {@link RunCommand} for example usage.
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010079 */
80 boolean binaryStdOut() default false;
81
82 /**
83 * Returns true if this command wants to write binary data to stderr.
84 * Enabling this flag will disable ANSI escape stripping for this command.
Shreya Bhattaraicd03ca22015-08-03 20:33:30 +000085 * This should be used in conjunction with {@code Reporter#switchToAnsiAllowingHandler}.
86 * See {@link RunCommand} for example usage.
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010087 */
88 boolean binaryStdErr() default false;
89
90 /**
Laszlo Csomor7f3ffbc2016-10-26 15:31:38 +000091 * Returns true if this command may want to write to the command.log.
92 *
93 * <p>The clean command would typically set this to false so it can delete the command.log.
94 */
95 boolean writeCommandLog() default true;
96
97 /**
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010098 * The help message for this command. If the value starts with "resource:",
99 * the remainder is interpreted as the name of a text file resource (in the
100 * .jar file that provides the Command implementation class).
101 */
102 String help();
103
104 /**
105 * Returns true iff this command may only be run from within a Blaze workspace. Broadly, this
106 * should be true for any command that interprets the package-path, since it's potentially
107 * confusing otherwise.
108 */
109 boolean mustRunInWorkspace() default true;
110
111 /**
112 * Returns true iff this command is allowed to run in the output directory,
113 * i.e. $OUTPUT_BASE/_blaze_$USER/$MD5/... . No command should be allowed to run here,
114 * but there are some legacy uses of 'blaze query'.
115 */
116 boolean canRunInOutputDirectory() default false;
117
Damien Martin-Guillerez29728d42015-04-09 20:48:04 +0000118 /**
119 * Returns the type completion help for this command, that is the type arguments that this command
120 * expects. It can be a whitespace separated list if the command take several arguments. The type
121 * of each arguments can be <code>label</code>, <code>path</code>, <code>string</code>, ...
122 * It can also be a comma separated list of values, e.g. <code>{value1,value2}<code>. If a command
123 * accept several argument types, they can be combined with |, e.g <code>label|path</code>.
124 */
125 String completion() default "";
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100126}