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 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 // Used for allocation-free lookups. | 249 // Used for allocation-free lookups. |
243 StringPieceSwitchMap switches_by_stringpiece_; | 250 StringPieceSwitchMap switches_by_stringpiece_; |
244 | 251 |
245 // The index after the program and switches, any arguments start here. | 252 // The index after the program and switches, any arguments start here. |
246 size_t begin_args_; | 253 size_t begin_args_; |
247 }; | 254 }; |
248 | 255 |
249 } // namespace base | 256 } // namespace base |
250 | 257 |
251 #endif // BASE_COMMAND_LINE_H_ | 258 #endif // BASE_COMMAND_LINE_H_ |
OLD | NEW |