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 <algorithm> | 5 #include <algorithm> |
6 #include <iostream> | 6 #include <iostream> |
7 | 7 |
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/functions.h" | 10 #include "tools/gn/functions.h" |
11 #include "tools/gn/input_conversion.h" | 11 #include "tools/gn/input_conversion.h" |
12 #include "tools/gn/setup.h" | 12 #include "tools/gn/setup.h" |
13 #include "tools/gn/standard_out.h" | 13 #include "tools/gn/standard_out.h" |
| 14 #include "tools/gn/variables.h" |
14 | 15 |
15 namespace commands { | 16 namespace commands { |
16 | 17 |
17 namespace { | 18 namespace { |
18 | 19 |
19 // Prints a line for a command, assuming there is a colon. Everything before | 20 // Prints a line for a command, assuming there is a colon. Everything before |
20 // the colon is the command (and is highlighted) and everything after it is | 21 // the colon is the command (and is highlighted) and everything after it is |
21 // normal. | 22 // normal. |
22 void PrintShortHelp(const std::string& line) { | 23 void PrintShortHelp(const std::string& line) { |
23 size_t colon_offset = line.find(':'); | 24 size_t colon_offset = line.find(':'); |
24 size_t first_normal = 0; | 25 size_t first_normal = 0; |
25 if (colon_offset != std::string::npos) { | 26 if (colon_offset != std::string::npos) { |
26 OutputString(" " + line.substr(0, colon_offset), DECORATION_YELLOW); | 27 OutputString(" " + line.substr(0, colon_offset), DECORATION_YELLOW); |
27 first_normal = colon_offset; | 28 first_normal = colon_offset; |
28 } | 29 } |
29 OutputString(line.substr(first_normal) + "\n"); | 30 OutputString(line.substr(first_normal) + "\n"); |
30 } | 31 } |
31 | 32 |
32 void PrintToplevelHelp() { | 33 void PrintToplevelHelp() { |
33 std::cout << | 34 OutputString("Commands (type \"gn help <command>\" for more details):\n"); |
34 "Commands (type \"gn help <command>\" for more details):\n"; | |
35 | 35 |
36 const commands::CommandInfoMap& command_map = commands::GetCommands(); | 36 const commands::CommandInfoMap& command_map = commands::GetCommands(); |
37 for (commands::CommandInfoMap::const_iterator i = command_map.begin(); | 37 for (commands::CommandInfoMap::const_iterator i = command_map.begin(); |
38 i != command_map.end(); ++i) | 38 i != command_map.end(); ++i) |
39 PrintShortHelp(i->second.help_short); | 39 PrintShortHelp(i->second.help_short); |
40 | 40 |
41 OutputString( | 41 OutputString( |
42 "\n" | 42 "\n" |
43 " When run with no arguments \"gn gen\" is assumed.\n" | 43 " When run with no arguments \"gn gen\" is assumed.\n" |
44 "\n" | 44 "\n" |
45 "Common switches:\n" | 45 "Common switches:\n" |
46 " -q: Quiet mode, don't print anything on success.\n" | 46 " -q: Quiet mode, don't print anything on success.\n" |
47 " --root: Specifies source root (overrides .gn file).\n" | 47 " --root: Specifies source root (overrides .gn file).\n" |
48 " --secondary: Specifies secondary source root (overrides .gn file).\n" | 48 " --secondary: Specifies secondary source root (overrides .gn file).\n" |
49 " -v: Verbose mode, print lots of logging.\n" | 49 " -v: Verbose mode, print lots of logging.\n"); |
50 "\n" | |
51 "Buildfile functions (type \"gn help <function>\" for more details):\n"); | |
52 | 50 |
| 51 // Functions. |
| 52 OutputString("\nBuildfile functions (type \"gn help <function>\" for more " |
| 53 "details):\n"); |
53 const functions::FunctionInfoMap& function_map = functions::GetFunctions(); | 54 const functions::FunctionInfoMap& function_map = functions::GetFunctions(); |
54 std::vector<std::string> sorted_functions; | 55 std::vector<std::string> sorted_functions; |
55 for (functions::FunctionInfoMap::const_iterator i = function_map.begin(); | 56 for (functions::FunctionInfoMap::const_iterator i = function_map.begin(); |
56 i != function_map.end(); ++i) | 57 i != function_map.end(); ++i) |
57 sorted_functions.push_back(i->first.as_string()); | 58 sorted_functions.push_back(i->first.as_string()); |
58 std::sort(sorted_functions.begin(), sorted_functions.end()); | 59 std::sort(sorted_functions.begin(), sorted_functions.end()); |
59 for (size_t i = 0; i < sorted_functions.size(); i++) | 60 for (size_t i = 0; i < sorted_functions.size(); i++) |
60 OutputString(" " + sorted_functions[i] + "\n", DECORATION_YELLOW); | 61 OutputString(" " + sorted_functions[i] + "\n", DECORATION_YELLOW); |
61 | 62 |
| 63 // Built-in variables. |
| 64 OutputString("\nBuilt-in predefined variables (type \"gn help <variable>\" " |
| 65 "for more details):\n"); |
| 66 const variables::VariableInfoMap& builtin_vars = |
| 67 variables::GetBuiltinVariables(); |
| 68 for (variables::VariableInfoMap::const_iterator i = builtin_vars.begin(); |
| 69 i != builtin_vars.end(); ++i) |
| 70 PrintShortHelp(i->second.help_short); |
| 71 |
| 72 // Target variables. |
| 73 OutputString("\nVariables you set in targets (type \"gn help <variable>\" " |
| 74 "for more details):\n"); |
| 75 const variables::VariableInfoMap& target_vars = |
| 76 variables::GetTargetVariables(); |
| 77 for (variables::VariableInfoMap::const_iterator i = target_vars.begin(); |
| 78 i != target_vars.end(); ++i) |
| 79 PrintShortHelp(i->second.help_short); |
| 80 |
62 OutputString("\nOther help topics:\n"); | 81 OutputString("\nOther help topics:\n"); |
63 PrintShortHelp("dotfile: Info about the toplevel .gn file."); | 82 PrintShortHelp("dotfile: Info about the toplevel .gn file."); |
64 PrintShortHelp( | 83 PrintShortHelp( |
65 "input_conversion: Processing input from exec_script and read_file."); | 84 "input_conversion: Processing input from exec_script and read_file."); |
66 } | 85 } |
67 | 86 |
68 } // namespace | 87 } // namespace |
69 | 88 |
70 const char kHelp[] = "help"; | 89 const char kHelp[] = "help"; |
71 const char kHelp_HelpShort[] = | 90 const char kHelp_HelpShort[] = |
(...skipping 20 matching lines...) Expand all Loading... |
92 | 111 |
93 // Check functions. | 112 // Check functions. |
94 const functions::FunctionInfoMap& function_map = functions::GetFunctions(); | 113 const functions::FunctionInfoMap& function_map = functions::GetFunctions(); |
95 functions::FunctionInfoMap::const_iterator found_function = | 114 functions::FunctionInfoMap::const_iterator found_function = |
96 function_map.find(args[0]); | 115 function_map.find(args[0]); |
97 if (found_function != function_map.end()) { | 116 if (found_function != function_map.end()) { |
98 OutputString(found_function->second.help); | 117 OutputString(found_function->second.help); |
99 return 0; | 118 return 0; |
100 } | 119 } |
101 | 120 |
| 121 // Builtin variables. |
| 122 const variables::VariableInfoMap& builtin_vars = |
| 123 variables::GetBuiltinVariables(); |
| 124 variables::VariableInfoMap::const_iterator found_builtin_var = |
| 125 builtin_vars.find(args[0]); |
| 126 if (found_builtin_var != builtin_vars.end()) { |
| 127 OutputString(found_builtin_var->second.help); |
| 128 return 0; |
| 129 } |
| 130 |
| 131 // Target variables. |
| 132 const variables::VariableInfoMap& target_vars = |
| 133 variables::GetTargetVariables(); |
| 134 variables::VariableInfoMap::const_iterator found_target_var = |
| 135 target_vars.find(args[0]); |
| 136 if (found_target_var != target_vars.end()) { |
| 137 OutputString(found_target_var->second.help); |
| 138 return 0; |
| 139 } |
| 140 |
102 // Random other topics. | 141 // Random other topics. |
103 if (args[0] == "input_conversion") { | 142 if (args[0] == "input_conversion") { |
104 OutputString(kInputConversion_Help); | 143 OutputString(kInputConversion_Help); |
105 return 0; | 144 return 0; |
106 } if (args[0] == "dotfile") { | 145 } if (args[0] == "dotfile") { |
107 OutputString(kDotfile_Help); | 146 OutputString(kDotfile_Help); |
108 return 0; | 147 return 0; |
109 } | 148 } |
110 | 149 |
111 // No help on this. | 150 // No help on this. |
112 Err(Location(), "No help on \"" + args[0] + "\".").PrintToStdout(); | 151 Err(Location(), "No help on \"" + args[0] + "\".").PrintToStdout(); |
113 RunHelp(std::vector<std::string>()); | 152 RunHelp(std::vector<std::string>()); |
114 return 1; | 153 return 1; |
115 } | 154 } |
116 | 155 |
117 } // namespace commands | 156 } // namespace commands |
OLD | NEW |