Chromium Code Reviews| 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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 87 static bool InitializedForCurrentProcess(); | 87 static bool InitializedForCurrentProcess(); |
| 88 | 88 |
| 89 #if defined(OS_WIN) | 89 #if defined(OS_WIN) |
| 90 static CommandLine FromString(const std::wstring& command_line); | 90 static CommandLine FromString(const std::wstring& command_line); |
| 91 #endif | 91 #endif |
| 92 | 92 |
| 93 // Initialize from an argv vector. | 93 // Initialize from an argv vector. |
| 94 void InitFromArgv(int argc, const CharType* const* argv); | 94 void InitFromArgv(int argc, const CharType* const* argv); |
| 95 void InitFromArgv(const StringVector& argv); | 95 void InitFromArgv(const StringVector& argv); |
| 96 | 96 |
| 97 // Constructs and returns the represented command line string. | 97 // Constructs and returns the represented command line string. If the optional |
| 98 // CAUTION! This should be avoided on POSIX because quoting behavior is | 98 // |quote_placeholders| is true, assumes the command line contains |
| 99 // placeholders (eg, %1) and quotes any program or argument with a '%' in it. | |
| 100 // CAUTION! This method should be avoided on POSIX because quoting behavior is | |
| 99 // unclear. | 101 // unclear. |
| 100 StringType GetCommandLineString() const; | 102 StringType GetCommandLineString() const { |
| 103 return GetCommandLineString(false); | |
| 104 } | |
| 105 StringType GetCommandLineString(bool quote_placeholders) const; | |
| 101 | 106 |
| 102 // Constructs and returns the represented arguments string. | 107 // Constructs and returns the represented arguments string. If the optional |
| 103 // CAUTION! This should be avoided on POSIX because quoting behavior is | 108 // |quote_placeholders| is true, assumes the command line contains |
| 109 // placeholders (eg, %1) and quotes any argument with a '%' in it. | |
| 110 // CAUTION! This method should be avoided on POSIX because quoting behavior is | |
| 104 // unclear. | 111 // unclear. |
| 105 StringType GetArgumentsString() const; | 112 StringType GetArgumentsString() const { return GetArgumentsString(false); } |
| 113 StringType GetArgumentsString(bool quote_placeholders) const; | |
|
Mark Mentovai
2014/09/25 03:40:43
Overloading’s discouraged.
Let’s just give this o
Matt Giuca
2014/09/25 04:35:30
Done.
| |
| 106 | 114 |
| 107 // Returns the original command line string as a vector of strings. | 115 // Returns the original command line string as a vector of strings. |
| 108 const StringVector& argv() const { return argv_; } | 116 const StringVector& argv() const { return argv_; } |
| 109 | 117 |
| 110 // Get and Set the program part of the command line string (the first item). | 118 // Get and Set the program part of the command line string (the first item). |
| 111 FilePath GetProgram() const; | 119 FilePath GetProgram() const; |
| 112 void SetProgram(const FilePath& program); | 120 void SetProgram(const FilePath& program); |
| 113 | 121 |
| 114 // Returns true if this command line contains the given switch. | 122 // Returns true if this command line contains the given switch. |
| 115 // (Switch names are case-insensitive). | 123 // (Switch names are case-insensitive). |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 185 // The index after the program and switches, any arguments start here. | 193 // The index after the program and switches, any arguments start here. |
| 186 size_t begin_args_; | 194 size_t begin_args_; |
| 187 }; | 195 }; |
| 188 | 196 |
| 189 } // namespace base | 197 } // namespace base |
| 190 | 198 |
| 191 // TODO(brettw) remove once all callers specify the namespace properly. | 199 // TODO(brettw) remove once all callers specify the namespace properly. |
| 192 using base::CommandLine; | 200 using base::CommandLine; |
| 193 | 201 |
| 194 #endif // BASE_COMMAND_LINE_H_ | 202 #endif // BASE_COMMAND_LINE_H_ |
| OLD | NEW |