OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // This class works with command lines: building and parsing. | 5 // This class works with command lines: building and parsing. |
6 // Arguments with prefixes ('--', '-', and on Windows, '/') are switches. | 6 // Arguments with prefixes ('--', '-', and on Windows, '/') are switches. |
7 // Switches will precede all other arguments without switch prefixes. | 7 // Switches will precede all other arguments without switch prefixes. |
8 // Switches can optionally have values, delimited by '=', e.g., "-switch=value". | 8 // Switches can optionally have values, delimited by '=', e.g., "-switch=value". |
9 // An argument of "--" will terminate switch parsing during initialization, | 9 // An argument of "--" will terminate switch parsing during initialization, |
10 // interpreting subsequent tokens as non-switch arguments, regardless of prefix. | 10 // interpreting subsequent tokens as non-switch arguments, regardless of prefix. |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 | 62 |
63 #if defined(OS_WIN) | 63 #if defined(OS_WIN) |
64 // By default this class will treat command-line arguments beginning with | 64 // By default this class will treat command-line arguments beginning with |
65 // slashes as switches on Windows, but not other platforms. | 65 // slashes as switches on Windows, but not other platforms. |
66 // | 66 // |
67 // If this behavior is inappropriate for your application, you can call this | 67 // If this behavior is inappropriate for your application, you can call this |
68 // function BEFORE initializing the current process' global command line | 68 // function BEFORE initializing the current process' global command line |
69 // object and the behavior will be the same as Posix systems (only hyphens | 69 // object and the behavior will be the same as Posix systems (only hyphens |
70 // begin switches, everything else will be an arg). | 70 // begin switches, everything else will be an arg). |
71 static void set_slash_is_not_a_switch(); | 71 static void set_slash_is_not_a_switch(); |
| 72 |
| 73 // Normally when the CommandLine singleton is initialized it gets the command |
| 74 // line via the GetCommandLineW API and then uses the shell32 API |
| 75 // CommandLineToArgvW to parse the command line and convert it back to |
| 76 // argc and argv. Tests who don't want this dependency on shell32 and need |
| 77 // to honor the arguments passed in should use this function. |
| 78 static void InitUsingArgvForTesting(int argc, const char* const* argv); |
72 #endif | 79 #endif |
73 | 80 |
74 // Initialize the current process CommandLine singleton. On Windows, ignores | 81 // Initialize the current process CommandLine singleton. On Windows, ignores |
75 // its arguments (we instead parse GetCommandLineW() directly) because we | 82 // its arguments (we instead parse GetCommandLineW() directly) because we |
76 // don't trust the CRT's parsing of the command line, but it still must be | 83 // don't trust the CRT's parsing of the command line, but it still must be |
77 // called to set up the command line. Returns false if initialization has | 84 // called to set up the command line. Returns false if initialization has |
78 // already occurred, and true otherwise. Only the caller receiving a 'true' | 85 // already occurred, and true otherwise. Only the caller receiving a 'true' |
79 // return value should take responsibility for calling Reset. | 86 // return value should take responsibility for calling Reset. |
80 static bool Init(int argc, const char* const* argv); | 87 static bool Init(int argc, const char* const* argv); |
81 | 88 |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 | 209 |
203 #if defined(OS_WIN) | 210 #if defined(OS_WIN) |
204 // Initialize by parsing the given command line string. | 211 // Initialize by parsing the given command line string. |
205 // The program name is assumed to be the first item in the string. | 212 // The program name is assumed to be the first item in the string. |
206 void ParseFromString(const base::string16& command_line); | 213 void ParseFromString(const base::string16& command_line); |
207 #endif | 214 #endif |
208 | 215 |
209 private: | 216 private: |
210 // Disallow default constructor; a program name must be explicitly specified. | 217 // Disallow default constructor; a program name must be explicitly specified. |
211 CommandLine(); | 218 CommandLine(); |
| 219 |
212 // Allow the copy constructor. A common pattern is to copy of the current | 220 // Allow the copy constructor. A common pattern is to copy of the current |
213 // process's command line and then add some flags to it. For example: | 221 // process's command line and then add some flags to it. For example: |
214 // CommandLine cl(*CommandLine::ForCurrentProcess()); | 222 // CommandLine cl(*CommandLine::ForCurrentProcess()); |
215 // cl.AppendSwitch(...); | 223 // cl.AppendSwitch(...); |
216 | 224 |
217 // Internal version of GetCommandLineString. If |quote_placeholders| is true, | 225 // Internal version of GetCommandLineString. If |quote_placeholders| is true, |
218 // also quotes parts with '%' in them. | 226 // also quotes parts with '%' in them. |
219 StringType GetCommandLineStringInternal(bool quote_placeholders) const; | 227 StringType GetCommandLineStringInternal(bool quote_placeholders) const; |
220 | 228 |
221 // Internal version of GetArgumentsString. If |quote_placeholders| is true, | 229 // Internal version of GetArgumentsString. If |quote_placeholders| is true, |
(...skipping 20 matching lines...) Expand all Loading... |
242 // Used for allocation-free lookups. | 250 // Used for allocation-free lookups. |
243 StringPieceSwitchMap switches_by_stringpiece_; | 251 StringPieceSwitchMap switches_by_stringpiece_; |
244 | 252 |
245 // The index after the program and switches, any arguments start here. | 253 // The index after the program and switches, any arguments start here. |
246 size_t begin_args_; | 254 size_t begin_args_; |
247 }; | 255 }; |
248 | 256 |
249 } // namespace base | 257 } // namespace base |
250 | 258 |
251 #endif // BASE_COMMAND_LINE_H_ | 259 #endif // BASE_COMMAND_LINE_H_ |
OLD | NEW |