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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 | 46 |
47 // Construct a new command line with |program| as argv[0]. | 47 // Construct a new command line with |program| as argv[0]. |
48 explicit CommandLine(const base::FilePath& program); | 48 explicit CommandLine(const base::FilePath& program); |
49 | 49 |
50 // Construct a new command line from an argument list. | 50 // Construct a new command line from an argument list. |
51 CommandLine(int argc, const CharType* const* argv); | 51 CommandLine(int argc, const CharType* const* argv); |
52 explicit CommandLine(const StringVector& argv); | 52 explicit CommandLine(const StringVector& argv); |
53 | 53 |
54 ~CommandLine(); | 54 ~CommandLine(); |
55 | 55 |
| 56 #if defined(OS_WIN) |
| 57 // By default this class will treat command-line arguments beginning with |
| 58 // slashes as switches on Windows, but not other platforms. |
| 59 // |
| 60 // If this behavior is inappropriate for your application, you can call this |
| 61 // function BEFORE initializing the current process' global command line |
| 62 // object and the behavior will be the same as Posix systems (only hyphens |
| 63 // begin switches, everything else will be an arg). |
| 64 static void set_slash_is_not_a_switch(); |
| 65 #endif |
| 66 |
56 // Initialize the current process CommandLine singleton. On Windows, ignores | 67 // Initialize the current process CommandLine singleton. On Windows, ignores |
57 // its arguments (we instead parse GetCommandLineW() directly) because we | 68 // its arguments (we instead parse GetCommandLineW() directly) because we |
58 // don't trust the CRT's parsing of the command line, but it still must be | 69 // don't trust the CRT's parsing of the command line, but it still must be |
59 // called to set up the command line. Returns false if initialization has | 70 // called to set up the command line. Returns false if initialization has |
60 // already occurred, and true otherwise. Only the caller receiving a 'true' | 71 // already occurred, and true otherwise. Only the caller receiving a 'true' |
61 // return value should take responsibility for calling Reset. | 72 // return value should take responsibility for calling Reset. |
62 static bool Init(int argc, const char* const* argv); | 73 static bool Init(int argc, const char* const* argv); |
63 | 74 |
64 // Destroys the current process CommandLine singleton. This is necessary if | 75 // Destroys the current process CommandLine singleton. This is necessary if |
65 // you want to reset the base library to its initial state (for example, in an | 76 // you want to reset the base library to its initial state (for example, in an |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 StringVector argv_; | 180 StringVector argv_; |
170 | 181 |
171 // Parsed-out switch keys and values. | 182 // Parsed-out switch keys and values. |
172 SwitchMap switches_; | 183 SwitchMap switches_; |
173 | 184 |
174 // The index after the program and switches, any arguments start here. | 185 // The index after the program and switches, any arguments start here. |
175 size_t begin_args_; | 186 size_t begin_args_; |
176 }; | 187 }; |
177 | 188 |
178 #endif // BASE_COMMAND_LINE_H_ | 189 #endif // BASE_COMMAND_LINE_H_ |
OLD | NEW |