Damien Martin-Guillerez | f88f4d8 | 2015-09-25 13:56:55 +0000 | [diff] [blame] | 1 | // Copyright 2014 The Bazel Authors. All rights reserved. |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 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. |
| 14 | package com.google.devtools.build.lib.runtime; |
| 15 | |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 16 | import com.google.devtools.common.options.OptionsParser; |
juliexxia | e91a450 | 2018-08-15 14:42:29 -0700 | [diff] [blame] | 17 | import com.google.devtools.common.options.OptionsParsingResult; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 18 | |
| 19 | /** |
juliexxia | e91a450 | 2018-08-15 14:42:29 -0700 | [diff] [blame] | 20 | * Interface implemented by Blaze commands. In addition to implementing this interface, each command |
| 21 | * must be annotated with a {@link Command} annotation. |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 22 | */ |
| 23 | public interface BlazeCommand { |
| 24 | /** |
juliexxia | e91a450 | 2018-08-15 14:42:29 -0700 | [diff] [blame] | 25 | * 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 |
brandjon | ba03c11 | 2017-03-31 17:39:53 +0000 | [diff] [blame] | 30 | * Command#options()}. The command indicates success / failure via its return value, which becomes |
lberki | 92125f8 | 2018-02-06 07:32:07 -0800 | [diff] [blame] | 31 | * 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 Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 34 | * |
Ulf Adams | 633f539 | 2015-09-15 11:13:08 +0000 | [diff] [blame] | 35 | * @param env The environment for the current command invocation |
brandjon | ba03c11 | 2017-03-31 17:39:53 +0000 | [diff] [blame] | 36 | * @param options A parsed options instance initialized with the values for the options specified |
| 37 | * in {@link Command#options()}. |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 38 | * @return The Unix exit status for the Blaze client. |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 39 | */ |
juliexxia | e91a450 | 2018-08-15 14:42:29 -0700 | [diff] [blame] | 40 | BlazeCommandResult exec(CommandEnvironment env, OptionsParsingResult options); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 41 | |
| 42 | /** |
juliexxia | e91a450 | 2018-08-15 14:42:29 -0700 | [diff] [blame] | 43 | * 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 Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 45 | * |
Ulf Adams | 633f539 | 2015-09-15 11:13:08 +0000 | [diff] [blame] | 46 | * @param optionsParser the options parser for the current command |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 47 | */ |
twerth | 28b9306 | 2020-01-10 00:07:45 -0800 | [diff] [blame] | 48 | default void editOptions(OptionsParser optionsParser) {} |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 49 | } |