1
1
// Copyright 2013 The Flutter Authors. All rights reserved.
2
2
// Use of this source code is governed by a BSD-style license that can be
3
3
// found in the LICENSE file.
4
- // FLUTTER_NOLINT
5
4
6
5
#include " flutter/fml/command_line.h"
7
6
@@ -27,8 +26,9 @@ CommandLine::CommandLine(const std::string& argv0,
27
26
argv0_ (argv0),
28
27
options_(options),
29
28
positional_args_(positional_args) {
30
- for (size_t i = 0 ; i < options_.size (); i++)
29
+ for (size_t i = 0 ; i < options_.size (); i++) {
31
30
option_index_[options_[i].name ] = i;
31
+ }
32
32
}
33
33
34
34
CommandLine::~CommandLine () = default ;
@@ -39,18 +39,21 @@ CommandLine& CommandLine::operator=(CommandLine&& from) = default;
39
39
40
40
bool CommandLine::HasOption (std::string_view name, size_t * index) const {
41
41
auto it = option_index_.find (name.data ());
42
- if (it == option_index_.end ())
42
+ if (it == option_index_.end ()) {
43
43
return false ;
44
- if (index)
44
+ }
45
+ if (index) {
45
46
*index = it->second ;
47
+ }
46
48
return true ;
47
49
}
48
50
49
51
bool CommandLine::GetOptionValue (std::string_view name,
50
52
std::string* value) const {
51
53
size_t index;
52
- if (!HasOption (name, &index))
54
+ if (!HasOption (name, &index)) {
53
55
return false ;
56
+ }
54
57
*value = options_[index].value ;
55
58
return true ;
56
59
}
@@ -59,8 +62,9 @@ std::vector<std::string_view> CommandLine::GetOptionValues(
59
62
std::string_view name) const {
60
63
std::vector<std::string_view> ret;
61
64
for (const auto & option : options_) {
62
- if (option.name == name)
65
+ if (option.name == name) {
63
66
ret.push_back (option.value );
67
+ }
64
68
}
65
69
return ret;
66
70
}
@@ -69,8 +73,9 @@ std::string CommandLine::GetOptionValueWithDefault(
69
73
std::string_view name,
70
74
std::string_view default_value) const {
71
75
size_t index;
72
- if (!HasOption (name, &index))
76
+ if (!HasOption (name, &index)) {
73
77
return {default_value.data (), default_value.size ()};
78
+ }
74
79
return options_[index].value ;
75
80
}
76
81
@@ -125,16 +130,18 @@ bool CommandLineBuilder::ProcessArg(const std::string& arg) {
125
130
}
126
131
127
132
CommandLine CommandLineBuilder::Build () const {
128
- if (!has_argv0_)
133
+ if (!has_argv0_) {
129
134
return CommandLine ();
135
+ }
130
136
return CommandLine (argv0_, options_, positional_args_);
131
137
}
132
138
133
139
} // namespace internal
134
140
135
141
std::vector<std::string> CommandLineToArgv (const CommandLine& command_line) {
136
- if (!command_line.has_argv0 ())
142
+ if (!command_line.has_argv0 ()) {
137
143
return std::vector<std::string>();
144
+ }
138
145
139
146
std::vector<std::string> argv;
140
147
const std::vector<CommandLine::Option>& options = command_line.options ();
@@ -146,17 +153,19 @@ std::vector<std::string> CommandLineToArgv(const CommandLine& command_line) {
146
153
147
154
argv.push_back (command_line.argv0 ());
148
155
for (const auto & option : options) {
149
- if (option.value .empty ())
156
+ if (option.value .empty ()) {
150
157
argv.push_back (" --" + option.name );
151
- else
158
+ } else {
152
159
argv.push_back (" --" + option.name + " =" + option.value );
160
+ }
153
161
}
154
162
155
163
if (!positional_args.empty ()) {
156
164
// Insert a "--" if necessary.
157
165
if (positional_args[0 ].size () >= 2u && positional_args[0 ][0 ] == ' -' &&
158
- positional_args[0 ][1 ] == ' -' )
166
+ positional_args[0 ][1 ] == ' -' ) {
159
167
argv.push_back (" --" );
168
+ }
160
169
161
170
argv.insert (argv.end (), positional_args.begin (), positional_args.end ());
162
171
}
0 commit comments