5#include "flutter/fml/command_line.h"
23 const std::vector<Option>&
options,
29 for (
size_t i = 0;
i < options_.size();
i++) {
30 option_index_[options_[
i].name] =
i;
41 auto it = option_index_.find(
name.data());
42 if (it == option_index_.end()) {
52 std::string*
value)
const {
57 *
value = options_[index].value;
62 std::string_view
name)
const {
63 std::vector<std::string_view> ret;
64 for (
const auto& option : options_) {
65 if (option.name ==
name) {
66 ret.push_back(option.value);
73 std::string_view
name,
74 std::string_view default_value)
const {
77 return {default_value.data(), default_value.size()};
79 return options_[index].value;
98 if (started_positional_args_) {
99 bool rv = positional_args_.empty();
100 positional_args_.push_back(arg);
105 if (arg.size() < 2u || arg[0] !=
'-' || arg[1] !=
'-') {
106 bool rv = positional_args_.empty();
107 started_positional_args_ =
true;
108 positional_args_.push_back(arg);
113 if (arg.size() == 2u) {
114 started_positional_args_ =
true;
121 size_t equals_pos = arg.find(
'=', 3u);
122 if (equals_pos == std::string::npos) {
128 arg.substr(equals_pos + 1u)));
136 return CommandLine(argv0_, options_, positional_args_);
143 return std::vector<std::string>();
146 std::vector<std::string>
argv;
147 const std::vector<CommandLine::Option>&
options = command_line.
options();
148 const std::vector<std::string>& positional_args =
152 argv.reserve(1u +
options.size() + 1u + positional_args.size());
155 for (
const auto& option :
options) {
156 if (option.value.empty()) {
157 argv.push_back(
"--" + option.name);
159 argv.push_back(
"--" + option.name +
"=" + option.value);
163 if (!positional_args.empty()) {
165 if (positional_args[0].
size() >= 2u && positional_args[0][0] ==
'-' &&
166 positional_args[0][1] ==
'-') {
167 argv.push_back(
"--");
170 argv.insert(
argv.end(), positional_args.begin(), positional_args.end());
const std::string & argv0() const
CommandLine & operator=(const CommandLine &from)
const std::vector< Option > & options() const
std::vector< std::string_view > GetOptionValues(std::string_view name) const
const std::vector< std::string > & positional_args() const
std::string GetOptionValueWithDefault(std::string_view name, std::string_view default_value) const
bool HasOption(std::string_view name, size_t *index=nullptr) const
bool GetOptionValue(std::string_view name, std::string *value) const
CommandLine Build() const
bool ProcessArg(const std::string &arg)
DEF_SWITCHES_START aot vmservice shared library name
constexpr std::size_t size(T(&array)[N])
std::vector< std::string > CommandLineToArgv(const CommandLine &command_line)