Android-cuttlefish cvd tool
command_request.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2022 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#pragma once
18
19#include <sys/socket.h>
20#include <sys/types.h>
21
22#include <initializer_list>
23#include <string>
24#include <unordered_map>
25#include <vector>
26
27#include "absl/strings/string_view.h"
28
31
32namespace cuttlefish {
33
35 public:
36 const std::unordered_map<std::string, std::string>& Env() const {
37 return env_;
38 }
39
41
42 const std::string& Subcommand() const { return subcommand_; }
43 const std::vector<std::string>& SubcommandArguments() const {
45 }
46
47 private:
49 CommandRequest(std::vector<std::string> args,
50 std::unordered_map<std::string, std::string> env,
52
53 std::vector<std::string> args_;
54 std::unordered_map<std::string, std::string> env_;
56
57 std::string subcommand_;
58 std::vector<std::string> subcommand_arguments_;
59};
60
62 public:
64
65 template <typename T>
67 for (auto&& arg : args) {
68 args_.emplace_back(arg);
69 }
70 return *this;
71 }
72
73 template <typename T>
75 for (auto&& arg : args) {
76 args_.emplace_back(arg);
77 }
78 return *this;
79 }
80
82 std::initializer_list<absl::string_view>) &;
84 std::initializer_list<absl::string_view>) &&;
85
87 selector::SelectorOptions selectors) & {
88 selector_options_ = std::move(selectors);
89 return *this;
90 }
91
93 selector::SelectorOptions selectors) && {
94 selector_options_ = std::move(selectors);
95 return *this;
96 }
97
98 CommandRequestBuilder& SetEnv(std::unordered_map<std::string, std::string>) &;
99 CommandRequestBuilder SetEnv(std::unordered_map<std::string, std::string>) &&;
100
101 CommandRequestBuilder& AddEnvVar(std::string key, std::string val) &;
102 CommandRequestBuilder AddEnvVar(std::string key, std::string val) &&;
103
105
106 private:
107 std::vector<std::string> args_;
108 std::unordered_map<std::string, std::string> env_;
110};
111
112// e.g. cvd start --help, cvd stop -help, cvd fleet -h
113Result<bool> HasHelpFlag(const std::vector<std::string>& args);
114
115} // namespace cuttlefish
Definition: command_request.h:61
CommandRequestBuilder SetSelectorOptions(selector::SelectorOptions selectors) &&
Definition: command_request.h:92
selector::SelectorOptions selector_options_
Definition: command_request.h:109
std::unordered_map< std::string, std::string > env_
Definition: command_request.h:108
CommandRequestBuilder & AddEnvVar(std::string key, std::string val) &
Definition: command_request.cpp:101
CommandRequestBuilder & AddArguments(T &&args) &
Definition: command_request.h:66
CommandRequestBuilder & SetSelectorOptions(selector::SelectorOptions selectors) &
Definition: command_request.h:86
std::vector< std::string > args_
Definition: command_request.h:107
CommandRequestBuilder AddArguments(T &&args) &&
Definition: command_request.h:74
CommandRequestBuilder & SetEnv(std::unordered_map< std::string, std::string >) &
Definition: command_request.cpp:89
Result< CommandRequest > Build() &&
Definition: command_request.cpp:113
Definition: command_request.h:34
const std::unordered_map< std::string, std::string > & Env() const
Definition: command_request.h:36
selector::SelectorOptions selectors_
Definition: command_request.h:55
std::vector< std::string > subcommand_arguments_
Definition: command_request.h:58
CommandRequest(std::vector< std::string > args, std::unordered_map< std::string, std::string > env, selector::SelectorOptions selectors)
Definition: command_request.cpp:52
std::unordered_map< std::string, std::string > env_
Definition: command_request.h:54
const std::string & Subcommand() const
Definition: command_request.h:42
const std::vector< std::string > & SubcommandArguments() const
Definition: command_request.h:43
const selector::SelectorOptions & Selectors() const
Definition: command_request.h:40
std::string subcommand_
Definition: command_request.h:57
std::vector< std::string > args_
Definition: command_request.h:53
Definition: alloc_driver.h:21
tl::expected< T, StackTraceError< E > > Result
Definition: result_type.h:30
Result< bool > HasHelpFlag(const std::vector< std::string > &args)
Definition: command_request.cpp:118
Definition: selector_common_parser.h:28