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
3 // found in the LICENSE file.
5 #include "base/at_exit.h"
6 #include "base/command_line.h"
7 #include "base/strings/utf_string_conversions.h"
8 #include "tools/gn/commands.h"
9 #include "tools/gn/err.h"
10 #include "tools/gn/location.h"
14 std::vector<std::string> GetArgs(const CommandLine& cmdline) {
15 CommandLine::StringVector in_args = cmdline.GetArgs();
17 std::vector<std::string> out_args;
18 for (size_t i = 0; i < in_args.size(); i++)
19 out_args.push_back(base::WideToUTF8(in_args[i]));
28 int main(int argc, char** argv) {
29 base::AtExitManager at_exit;
31 CommandLine::set_slash_is_not_a_switch();
33 CommandLine::Init(argc, argv);
35 const CommandLine& cmdline = *CommandLine::ForCurrentProcess();
36 std::vector<std::string> args = GetArgs(cmdline);
39 if (cmdline.HasSwitch("help")) {
40 // Make "--help" default to help command.
41 command = commands::kHelp;
42 } else if (args.empty()) {
43 command = commands::kGen;
46 args.erase(args.begin());
49 const commands::CommandInfoMap& command_map = commands::GetCommands();
50 commands::CommandInfoMap::const_iterator found_command =
51 command_map.find(command);
54 if (found_command != command_map.end()) {
55 retval = found_command->second.runner(args);
58 "Command \"" + command + "\" unknown.").PrintToStdout();
59 commands::RunHelp(std::vector<std::string>());
63 exit(retval); // Don't free memory, it can be really slow!