11// Copyright 2013 The Flutter Authors. All rights reserved.
22// Use of this source code is governed by a BSD-style license that can be
33// found in the LICENSE file.
4- // FLUTTER_NOLINT
54
65#include " flutter/fml/command_line.h"
76
@@ -27,8 +26,9 @@ CommandLine::CommandLine(const std::string& argv0,
2726 argv0_ (argv0),
2827 options_(options),
2928 positional_args_(positional_args) {
30- for (size_t i = 0 ; i < options_.size (); i++)
29+ for (size_t i = 0 ; i < options_.size (); i++) {
3130 option_index_[options_[i].name ] = i;
31+ }
3232}
3333
3434CommandLine::~CommandLine () = default ;
@@ -39,18 +39,21 @@ CommandLine& CommandLine::operator=(CommandLine&& from) = default;
3939
4040bool CommandLine::HasOption (std::string_view name, size_t * index) const {
4141 auto it = option_index_.find (name.data ());
42- if (it == option_index_.end ())
42+ if (it == option_index_.end ()) {
4343 return false ;
44- if (index)
44+ }
45+ if (index) {
4546 *index = it->second ;
47+ }
4648 return true ;
4749}
4850
4951bool CommandLine::GetOptionValue (std::string_view name,
5052 std::string* value) const {
5153 size_t index;
52- if (!HasOption (name, &index))
54+ if (!HasOption (name, &index)) {
5355 return false ;
56+ }
5457 *value = options_[index].value ;
5558 return true ;
5659}
@@ -59,8 +62,9 @@ std::vector<std::string_view> CommandLine::GetOptionValues(
5962 std::string_view name) const {
6063 std::vector<std::string_view> ret;
6164 for (const auto & option : options_) {
62- if (option.name == name)
65+ if (option.name == name) {
6366 ret.push_back (option.value );
67+ }
6468 }
6569 return ret;
6670}
@@ -69,8 +73,9 @@ std::string CommandLine::GetOptionValueWithDefault(
6973 std::string_view name,
7074 std::string_view default_value) const {
7175 size_t index;
72- if (!HasOption (name, &index))
76+ if (!HasOption (name, &index)) {
7377 return {default_value.data (), default_value.size ()};
78+ }
7479 return options_[index].value ;
7580}
7681
@@ -125,16 +130,18 @@ bool CommandLineBuilder::ProcessArg(const std::string& arg) {
125130}
126131
127132CommandLine CommandLineBuilder::Build () const {
128- if (!has_argv0_)
133+ if (!has_argv0_) {
129134 return CommandLine ();
135+ }
130136 return CommandLine (argv0_, options_, positional_args_);
131137}
132138
133139} // namespace internal
134140
135141std::vector<std::string> CommandLineToArgv (const CommandLine& command_line) {
136- if (!command_line.has_argv0 ())
142+ if (!command_line.has_argv0 ()) {
137143 return std::vector<std::string>();
144+ }
138145
139146 std::vector<std::string> argv;
140147 const std::vector<CommandLine::Option>& options = command_line.options ();
@@ -146,17 +153,19 @@ std::vector<std::string> CommandLineToArgv(const CommandLine& command_line) {
146153
147154 argv.push_back (command_line.argv0 ());
148155 for (const auto & option : options) {
149- if (option.value .empty ())
156+ if (option.value .empty ()) {
150157 argv.push_back (" --" + option.name );
151- else
158+ } else {
152159 argv.push_back (" --" + option.name + " =" + option.value );
160+ }
153161 }
154162
155163 if (!positional_args.empty ()) {
156164 // Insert a "--" if necessary.
157165 if (positional_args[0 ].size () >= 2u && positional_args[0 ][0 ] == ' -' &&
158- positional_args[0 ][1 ] == ' -' )
166+ positional_args[0 ][1 ] == ' -' ) {
159167 argv.push_back (" --" );
168+ }
160169
161170 argv.insert (argv.end (), positional_args.begin (), positional_args.end ());
162171 }
0 commit comments