aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/cpp/option_processor.h
diff options
context:
space:
mode:
authorGravatar Luis Fernando Pino Duque <lpino@google.com>2016-11-21 13:20:50 +0000
committerGravatar Dmitry Lomov <dslomov@google.com>2016-11-21 19:41:18 +0000
commit0311fc5ed3a1e789dc2c09eb5c44849b5507f46a (patch)
tree32dad2c046492c29a1feaa6f73548efc4985aa0f /src/main/cpp/option_processor.h
parent480a2cf4d3684ad9171077a279f1743192096d7b (diff)
Provide a SplitCommandLine method in the option processor
that takes a given command line args and splits it into the corresponding {binary, startup_args, command, command_args}. The purpose of this function is to help split the responsibilities of the ParseOptions function by processing the startup options independently (i.e. rc files detection and processing) from the command options. This will be combined with ParseOptions in a subsequent CL. -- MOS_MIGRATED_REVID=139773786
Diffstat (limited to 'src/main/cpp/option_processor.h')
-rw-r--r--src/main/cpp/option_processor.h39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/main/cpp/option_processor.h b/src/main/cpp/option_processor.h
index 472414de75..1281e77ed7 100644
--- a/src/main/cpp/option_processor.h
+++ b/src/main/cpp/option_processor.h
@@ -26,6 +26,22 @@
namespace blaze {
+struct CommandLine {
+ const std::string path_to_binary;
+ const std::vector<std::string> startup_args;
+ const std::string command;
+ const std::vector<std::string> command_args;
+
+ CommandLine(const std::string& path_to_binary_arg,
+ const std::vector<std::string>& startup_args_arg,
+ const std::string& command_arg,
+ const std::vector<std::string>& command_args_arg)
+ : path_to_binary(path_to_binary_arg),
+ startup_args(startup_args_arg),
+ command(command_arg),
+ command_args(command_args_arg) {}
+};
+
// This class is responsible for parsing the command line of the Blaze binary,
// parsing blazerc files, and putting together the command that should be sent
// to the server.
@@ -35,6 +51,29 @@ class OptionProcessor {
virtual ~OptionProcessor();
+ // Splits the arguments of a command line invocation.
+ //
+ // For instance:
+ // output/bazel --foo --bar=42 --bar blah build --myflag value :mytarget
+ //
+ // returns a CommandLine structure with the following values:
+ // result.path_to_binary = "output/bazel"
+ // result.startup_args = {"--foo", "--bar=42", "--bar=blah"}
+ // result.command = "build"
+ // result.command_args = {"--some_flag", "value", ":mytarget"}
+ //
+ // Note that result.startup_args is guaranteed to contain only valid
+ // startup options (w.r.t. StartupOptions::IsUnary and
+ // StartupOptions::IsNullary) and unary startup args of the form '--bar blah'
+ // are rewritten as '--bar=blah' for uniformity.
+ // In turn, the command and command args are not rewritten nor validated.
+ //
+ // If the method fails then error will contain the cause, otherwise error
+ // remains untouched.
+ std::unique_ptr<CommandLine> SplitCommandLine(
+ const std::vector<std::string>& args,
+ std::string* error);
+
// Parse a command line and the appropriate blazerc files. This should be
// invoked only once per OptionProcessor object.
blaze_exit_code::ExitCode ParseOptions(const std::vector<std::string>& args,