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 <string_view>
25#include <unordered_map>
26#include <vector>
27
30
31namespace cuttlefish {
32
34 public:
35 const std::unordered_map<std::string, std::string>& Env() const {
36 return env_;
37 }
38
40
41 const std::string& Subcommand() const { return subcommand_; }
42 const std::vector<std::string>& SubcommandArguments() const {
44 }
45
46 private:
48 CommandRequest(std::vector<std::string> args,
49 std::unordered_map<std::string, std::string> env,
51
52 std::vector<std::string> args_;
53 std::unordered_map<std::string, std::string> env_;
55
56 std::string subcommand_;
57 std::vector<std::string> subcommand_arguments_;
58};
59
61 public:
63
64 template <typename T>
66 for (auto&& arg : args) {
67 args_.emplace_back(arg);
68 }
69 return *this;
70 }
71
72 template <typename T>
74 for (auto&& arg : args) {
75 args_.emplace_back(arg);
76 }
77 return *this;
78 }
79
81 std::initializer_list<std::string_view>) &;
83 std::initializer_list<std::string_view>) &&;
84
86 selector::SelectorOptions selectors) & {
87 selector_options_ = std::move(selectors);
88 return *this;
89 }
90
92 selector::SelectorOptions selectors) && {
93 selector_options_ = std::move(selectors);
94 return *this;
95 }
96
97 CommandRequestBuilder& SetEnv(std::unordered_map<std::string, std::string>) &;
98 CommandRequestBuilder SetEnv(std::unordered_map<std::string, std::string>) &&;
99
100 CommandRequestBuilder& AddEnvVar(std::string key, std::string val) &;
101 CommandRequestBuilder AddEnvVar(std::string key, std::string val) &&;
102
104
105 private:
106 std::vector<std::string> args_;
107 std::unordered_map<std::string, std::string> env_;
109};
110
111// e.g. cvd start --help, cvd stop -help, cvd fleet -h
112Result<bool> HasHelpFlag(const std::vector<std::string>& args);
113
114} // namespace cuttlefish
Definition: command_request.h:60
CommandRequestBuilder SetSelectorOptions(selector::SelectorOptions selectors) &&
Definition: command_request.h:91
selector::SelectorOptions selector_options_
Definition: command_request.h:108
std::unordered_map< std::string, std::string > env_
Definition: command_request.h:107
CommandRequestBuilder & AddEnvVar(std::string key, std::string val) &
Definition: command_request.cpp:101
CommandRequestBuilder & AddArguments(T &&args) &
Definition: command_request.h:65
CommandRequestBuilder & SetSelectorOptions(selector::SelectorOptions selectors) &
Definition: command_request.h:85
std::vector< std::string > args_
Definition: command_request.h:106
CommandRequestBuilder AddArguments(T &&args) &&
Definition: command_request.h:73
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:33
const std::unordered_map< std::string, std::string > & Env() const
Definition: command_request.h:35
selector::SelectorOptions selectors_
Definition: command_request.h:54
std::vector< std::string > subcommand_arguments_
Definition: command_request.h:57
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:53
const std::string & Subcommand() const
Definition: command_request.h:41
const std::vector< std::string > & SubcommandArguments() const
Definition: command_request.h:42
const selector::SelectorOptions & Selectors() const
Definition: command_request.h:39
std::string subcommand_
Definition: command_request.h:56
std::vector< std::string > args_
Definition: command_request.h:52
#define key
Definition: dict.c:55
Definition: alloc_driver.h:20
tl::expected< T, StackTraceError > 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