blob: c0500438473efd600ca158a80d6cad95f211cd8c [file] [log] [blame]
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +01001// Copyright 2014 Google Inc. All rights reserved.
2//
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.build.lib.util.AbruptExitException;
17import com.google.devtools.build.lib.util.ExitCode;
18import com.google.devtools.common.options.OptionsParser;
19import com.google.devtools.common.options.OptionsProvider;
20
21/**
22 * Interface implemented by Blaze commands. In addition to implementing this interface, each
23 * command must be annotated with a {@link Command} annotation.
24 */
25public interface BlazeCommand {
26 /**
27 * This method provides the imperative portion of the command. It takes
28 * a {@link OptionsProvider} instance {@code options}, which provides access
29 * to the options instances via {@link OptionsProvider#getOptions(Class)},
30 * and access to the residue (the remainder of the command line) via
31 * {@link OptionsProvider#getResidue()}. The framework parses and makes
32 * available exactly the options that the command class specifies via the
33 * annotation {@link Command#options()}. The command may write to standard
34 * out and standard error via {@code outErr}. It indicates success / failure
35 * via its return value, which becomes the Unix exit status of the Blaze
36 * client process. It may indicate a shutdown request by throwing
37 * {@link BlazeCommandDispatcher.ShutdownBlazeServerException}. In that case,
38 * the Blaze server process (the memory resident portion of Blaze) will
39 * shut down and the exit status will be 0 (in case the shutdown succeeds
40 * without error).
41 *
Ulf Adams633f5392015-09-15 11:13:08 +000042 * @param env The environment for the current command invocation
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010043 * @param options A parsed options instance initialized with the values for
44 * the options specified in {@link Command#options()}.
45 *
46 * @return The Unix exit status for the Blaze client.
47 * @throws BlazeCommandDispatcher.ShutdownBlazeServerException Indicates
48 * that the command wants to shutdown the Blaze server.
49 */
Ulf Adams633f5392015-09-15 11:13:08 +000050 ExitCode exec(CommandEnvironment env, OptionsProvider options)
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010051 throws BlazeCommandDispatcher.ShutdownBlazeServerException;
52
53 /**
54 * Allows the command to provide command-specific option defaults and/or
55 * requirements. This method is called after all command-line and rc file options have been
56 * parsed.
57 *
Ulf Adams633f5392015-09-15 11:13:08 +000058 * @param env the command environment of the currently running command
59 * @param optionsParser the options parser for the current command
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010060 *
61 * @throws AbruptExitException if something went wrong
62 */
Ulf Adams633f5392015-09-15 11:13:08 +000063 void editOptions(CommandEnvironment env, OptionsParser optionsParser) throws AbruptExitException;
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010064}