blob: 676af76f511b93f5ccef841459e064e5f980b7ce [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
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010016import com.google.devtools.common.options.OptionsParser;
juliexxiae91a4502018-08-15 14:42:29 -070017import com.google.devtools.common.options.OptionsParsingResult;
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010018
19/**
juliexxiae91a4502018-08-15 14:42:29 -070020 * Interface implemented by Blaze commands. In addition to implementing this interface, each command
21 * must be annotated with a {@link Command} annotation.
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010022 */
23public interface BlazeCommand {
24 /**
juliexxiae91a4502018-08-15 14:42:29 -070025 * This method provides the imperative portion of the command. It takes a {@link
26 * OptionsParsingResult} instance {@code options}, which provides access to the options instances
27 * via {@link OptionsParsingResult#getOptions(Class)}, and access to the residue (the remainder of
28 * the command line) via {@link OptionsParsingResult#getResidue()}. The framework parses and makes
29 * available exactly the options that the command class specifies via the annotation {@link
brandjonba03c112017-03-31 17:39:53 +000030 * Command#options()}. The command indicates success / failure via its return value, which becomes
lberki92125f82018-02-06 07:32:07 -080031 * the Unix exit status of the Blaze client process. It may indicate that the server needs to be
32 * shut down or that a particular binary needs to be exec()ed on the terminal where Blaze was
33 * invoked from by returning the appropriate {@link BlazeCommandResult}.
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010034 *
Ulf Adams633f5392015-09-15 11:13:08 +000035 * @param env The environment for the current command invocation
brandjonba03c112017-03-31 17:39:53 +000036 * @param options A parsed options instance initialized with the values for the options specified
37 * in {@link Command#options()}.
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010038 * @return The Unix exit status for the Blaze client.
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010039 */
juliexxiae91a4502018-08-15 14:42:29 -070040 BlazeCommandResult exec(CommandEnvironment env, OptionsParsingResult options);
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010041
42 /**
juliexxiae91a4502018-08-15 14:42:29 -070043 * Allows the command to provide command-specific option defaults and/or requirements. This method
44 * is called after all command-line and rc file options have been parsed.
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010045 *
Ulf Adams633f5392015-09-15 11:13:08 +000046 * @param optionsParser the options parser for the current command
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010047 */
twerth28b93062020-01-10 00:07:45 -080048 default void editOptions(OptionsParser optionsParser) {}
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010049}