OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <stdio.h> | 5 #include <stdio.h> |
6 #include <stdlib.h> | 6 #include <stdlib.h> |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 Scope::KeyValueMap build_args; | 121 Scope::KeyValueMap build_args; |
122 setup->build_settings().build_args().MergeDeclaredArguments(&build_args); | 122 setup->build_settings().build_args().MergeDeclaredArguments(&build_args); |
123 | 123 |
124 // Find all of the arguments we care about. Use a regular map so they're | 124 // Find all of the arguments we care about. Use a regular map so they're |
125 // sorted nicely when we write them out. | 125 // sorted nicely when we write them out. |
126 std::map<base::StringPiece, Value> sorted_args; | 126 std::map<base::StringPiece, Value> sorted_args; |
127 std::string list_value = | 127 std::string list_value = |
128 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(kSwitchList); | 128 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(kSwitchList); |
129 if (list_value.empty()) { | 129 if (list_value.empty()) { |
130 // List all values. | 130 // List all values. |
131 for (Scope::KeyValueMap::const_iterator i = build_args.begin(); | 131 for (const auto& arg : build_args) |
132 i != build_args.end(); ++i) | 132 sorted_args.insert(arg); |
133 sorted_args.insert(*i); | |
134 } else { | 133 } else { |
135 // List just the one specified as the parameter to --list. | 134 // List just the one specified as the parameter to --list. |
136 Scope::KeyValueMap::const_iterator found_arg = build_args.find(list_value); | 135 Scope::KeyValueMap::const_iterator found_arg = build_args.find(list_value); |
137 if (found_arg == build_args.end()) { | 136 if (found_arg == build_args.end()) { |
138 Err(Location(), "Unknown build argument.", | 137 Err(Location(), "Unknown build argument.", |
139 "You asked for \"" + list_value + "\" which I didn't find in any " | 138 "You asked for \"" + list_value + "\" which I didn't find in any " |
140 "build file\nassociated with this build.").PrintToStdout(); | 139 "build file\nassociated with this build.").PrintToStdout(); |
141 return 1; | 140 return 1; |
142 } | 141 } |
143 sorted_args.insert(*found_arg); | 142 sorted_args.insert(*found_arg); |
144 } | 143 } |
145 | 144 |
146 if (base::CommandLine::ForCurrentProcess()->HasSwitch(kSwitchShort)) { | 145 if (base::CommandLine::ForCurrentProcess()->HasSwitch(kSwitchShort)) { |
147 // Short key=value output. | 146 // Short key=value output. |
148 for (std::map<base::StringPiece, Value>::iterator i = sorted_args.begin(); | 147 for (const auto& arg : sorted_args) { |
149 i != sorted_args.end(); ++i) { | 148 OutputString(arg.first.as_string()); |
150 OutputString(i->first.as_string()); | |
151 OutputString(" = "); | 149 OutputString(" = "); |
152 OutputString(i->second.ToString(true)); | 150 OutputString(arg.second.ToString(true)); |
153 OutputString("\n"); | 151 OutputString("\n"); |
154 } | 152 } |
155 return 0; | 153 return 0; |
156 } | 154 } |
157 | 155 |
158 // Long output. | 156 // Long output. |
159 for (std::map<base::StringPiece, Value>::iterator i = sorted_args.begin(); | 157 for (const auto& arg : sorted_args) { |
160 i != sorted_args.end(); ++i) { | 158 PrintArgHelp(arg.first, arg.second); |
161 PrintArgHelp(i->first, i->second); | |
162 OutputString("\n"); | 159 OutputString("\n"); |
163 } | 160 } |
164 | 161 |
165 return 0; | 162 return 0; |
166 } | 163 } |
167 | 164 |
168 #if defined(OS_WIN) | 165 #if defined(OS_WIN) |
169 | 166 |
170 bool RunEditor(const base::FilePath& file_to_edit) { | 167 bool RunEditor(const base::FilePath& file_to_edit) { |
171 SHELLEXECUTEINFO info; | 168 SHELLEXECUTEINFO info; |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 "Or see \"gn help args\" for more variants.").PrintToStdout(); | 335 "Or see \"gn help args\" for more variants.").PrintToStdout(); |
339 return 1; | 336 return 1; |
340 } | 337 } |
341 | 338 |
342 if (base::CommandLine::ForCurrentProcess()->HasSwitch(kSwitchList)) | 339 if (base::CommandLine::ForCurrentProcess()->HasSwitch(kSwitchList)) |
343 return ListArgs(args[0]); | 340 return ListArgs(args[0]); |
344 return EditArgsFile(args[0]); | 341 return EditArgsFile(args[0]); |
345 } | 342 } |
346 | 343 |
347 } // namespace commands | 344 } // namespace commands |
OLD | NEW |