| 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 "base/at_exit.h" | 5 #include "base/at_exit.h" |
| 6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "tools/gn/commands.h" | 8 #include "tools/gn/commands.h" |
| 9 #include "tools/gn/err.h" | 9 #include "tools/gn/err.h" |
| 10 #include "tools/gn/location.h" | 10 #include "tools/gn/location.h" |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 | 46 |
| 47 std::string command; | 47 std::string command; |
| 48 if (cmdline.HasSwitch("help") || cmdline.HasSwitch("h")) { | 48 if (cmdline.HasSwitch("help") || cmdline.HasSwitch("h")) { |
| 49 // Make "-h" and "--help" default to help command. | 49 // Make "-h" and "--help" default to help command. |
| 50 command = commands::kHelp; | 50 command = commands::kHelp; |
| 51 } else if (cmdline.HasSwitch("version")) { | 51 } else if (cmdline.HasSwitch("version")) { |
| 52 // Make "--version" print the version and exit. | 52 // Make "--version" print the version and exit. |
| 53 OutputString(std::string(LAST_CHANGE) + "\n"); | 53 OutputString(std::string(LAST_CHANGE) + "\n"); |
| 54 exit(0); | 54 exit(0); |
| 55 } else if (args.empty()) { | 55 } else if (args.empty()) { |
| 56 command = commands::kGen; | 56 // No command, print error and exit. |
| 57 Err(Location(), "No command specified.", |
| 58 "Most commonly you want \"gn gen <out_dir>\" to make a build dir.\n" |
| 59 "Or try \"gn help\" for more commands.").PrintToStdout(); |
| 60 return 1; |
| 57 } else { | 61 } else { |
| 58 command = args[0]; | 62 command = args[0]; |
| 59 args.erase(args.begin()); | 63 args.erase(args.begin()); |
| 60 } | 64 } |
| 61 | 65 |
| 62 const commands::CommandInfoMap& command_map = commands::GetCommands(); | 66 const commands::CommandInfoMap& command_map = commands::GetCommands(); |
| 63 commands::CommandInfoMap::const_iterator found_command = | 67 commands::CommandInfoMap::const_iterator found_command = |
| 64 command_map.find(command); | 68 command_map.find(command); |
| 65 | 69 |
| 66 int retval; | 70 int retval; |
| 67 if (found_command != command_map.end()) { | 71 if (found_command != command_map.end()) { |
| 68 retval = found_command->second.runner(args); | 72 retval = found_command->second.runner(args); |
| 69 } else { | 73 } else { |
| 70 Err(Location(), | 74 Err(Location(), |
| 71 "Command \"" + command + "\" unknown.").PrintToStdout(); | 75 "Command \"" + command + "\" unknown.").PrintToStdout(); |
| 72 commands::RunHelp(std::vector<std::string>()); | 76 commands::RunHelp(std::vector<std::string>()); |
| 73 retval = 1; | 77 retval = 1; |
| 74 } | 78 } |
| 75 | 79 |
| 76 exit(retval); // Don't free memory, it can be really slow! | 80 exit(retval); // Don't free memory, it can be really slow! |
| 77 return retval; | 81 return retval; |
| 78 } | 82 } |
| OLD | NEW |