| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 // Switches can optionally have a value attached using an equals sign, | 6 // Switches can optionally have a value attached using an equals sign, |
| 7 // as in "-switch=value". Arguments that aren't prefixed with a | 7 // as in "-switch=value". Arguments that aren't prefixed with a |
| 8 // switch prefix are saved as extra arguments. An argument of "--" | 8 // switch prefix are saved as extra arguments. An argument of "--" |
| 9 // will terminate switch parsing, causing everything after to be | 9 // will terminate switch parsing, causing everything after to be |
| 10 // considered as extra arguments. | 10 // considered as extra arguments. |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 // Returns true if this command line contains the given switch. | 94 // Returns true if this command line contains the given switch. |
| 95 // (Switch names are case-insensitive.) | 95 // (Switch names are case-insensitive.) |
| 96 bool HasSwitch(const std::string& switch_string) const; | 96 bool HasSwitch(const std::string& switch_string) const; |
| 97 | 97 |
| 98 // Deprecated version of the above. | 98 // Deprecated version of the above. |
| 99 bool HasSwitch(const std::wstring& switch_string) const; | 99 bool HasSwitch(const std::wstring& switch_string) const; |
| 100 | 100 |
| 101 // Returns the value associated with the given switch. If the | 101 // Returns the value associated with the given switch. If the |
| 102 // switch has no value or isn't present, this method returns | 102 // switch has no value or isn't present, this method returns |
| 103 // the empty string. | 103 // the empty string. |
| 104 // TODO(evanm): move these into command_line.cpp once we've fixed the | |
| 105 // wstringness. | |
| 106 std::string GetSwitchValueASCII(const std::string& switch_string) const; | 104 std::string GetSwitchValueASCII(const std::string& switch_string) const; |
| 107 FilePath GetSwitchValuePath(const std::string& switch_string) const; | 105 FilePath GetSwitchValuePath(const std::string& switch_string) const; |
| 106 StringType GetSwitchValueNative(const std::string& switch_string) const; |
| 108 | 107 |
| 109 // Deprecated versions of the above. | 108 // Deprecated versions of the above. |
| 110 std::wstring GetSwitchValue(const std::string& switch_string) const; | 109 std::wstring GetSwitchValue(const std::string& switch_string) const; |
| 111 std::wstring GetSwitchValue(const std::wstring& switch_string) const; | 110 std::wstring GetSwitchValue(const std::wstring& switch_string) const; |
| 112 | 111 |
| 113 // Get the number of switches in this process. | 112 // Get the number of switches in this process. |
| 114 size_t GetSwitchCount() const { return switches_.size(); } | 113 size_t GetSwitchCount() const { return switches_.size(); } |
| 115 | 114 |
| 116 // The type of map for parsed-out switch key and values. | 115 // The type of map for parsed-out switch key and values. |
| 117 typedef std::map<std::string, StringType> SwitchMap; | 116 typedef std::map<std::string, StringType> SwitchMap; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 // Return a copy of the string prefixed with a switch prefix. | 148 // Return a copy of the string prefixed with a switch prefix. |
| 150 // Used internally. | 149 // Used internally. |
| 151 static std::wstring PrefixedSwitchString(const std::string& switch_string); | 150 static std::wstring PrefixedSwitchString(const std::string& switch_string); |
| 152 | 151 |
| 153 // Return a copy of the string prefixed with a switch prefix, | 152 // Return a copy of the string prefixed with a switch prefix, |
| 154 // and appended with the given value. Used internally. | 153 // and appended with the given value. Used internally. |
| 155 static std::wstring PrefixedSwitchStringWithValue( | 154 static std::wstring PrefixedSwitchStringWithValue( |
| 156 const std::string& switch_string, | 155 const std::string& switch_string, |
| 157 const std::wstring& value_string); | 156 const std::wstring& value_string); |
| 158 | 157 |
| 159 // Appends the given switch string (preceded by a space and a switch | 158 // Append a switch to the command line. |
| 160 // prefix) to the given string. | |
| 161 void AppendSwitch(const std::string& switch_string); | 159 void AppendSwitch(const std::string& switch_string); |
| 162 | 160 |
| 163 // Appends the given switch string (preceded by a space and a switch | 161 // Append a switch and value to the command line. |
| 164 // prefix) to the given string, with the given value attached. | 162 void AppendSwitchPath(const std::string& switch_string, const FilePath& path); |
| 163 void AppendSwitchNative(const std::string& switch_string, |
| 164 const StringType& value); |
| 165 |
| 166 // Append a switch and value to the command line. |
| 167 // TODO(evanm): remove all AppendSwitchWithValue() instances. |
| 168 // TODO(evanm): add an *ASCII() version. |
| 165 void AppendSwitchWithValue(const std::string& switch_string, | 169 void AppendSwitchWithValue(const std::string& switch_string, |
| 166 const std::wstring& value_string); | 170 const std::wstring& value_string); |
| 167 void AppendSwitchWithValue(const std::string& switch_string, | 171 void AppendSwitchWithValue(const std::string& switch_string, |
| 168 const std::string& value_string); | 172 const std::string& value_string); |
| 169 | 173 |
| 170 // Append a loose value to the command line. | 174 // Append a loose value to the command line. |
| 171 void AppendLooseValue(const std::wstring& value); | 175 void AppendLooseValue(const std::wstring& value); |
| 172 | 176 |
| 173 // Append the arguments from another command line to this one. | 177 // Append the arguments from another command line to this one. |
| 174 // If |include_program| is true, include |other|'s program as well. | 178 // If |include_program| is true, include |other|'s program as well. |
| 175 void AppendArguments(const CommandLine& other, | 179 void AppendArguments(const CommandLine& other, |
| 176 bool include_program); | 180 bool include_program); |
| 177 | 181 |
| 178 // On POSIX systems it's common to run processes via a wrapper (like | 182 // On POSIX systems it's common to run processes via a wrapper (like |
| 179 // "valgrind" or "gdb --args"). | 183 // "valgrind" or "gdb --args"). |
| 180 void PrependWrapper(const std::wstring& wrapper); | 184 void PrependWrapper(const std::wstring& wrapper); |
| 181 | 185 |
| 186 // Copy a set of switches (and their values, if any) from another command |
| 187 // line. Commonly used when launching a subprocess. |
| 188 void CopySwitchesFrom(const CommandLine& source, const char* const switches[], |
| 189 size_t count); |
| 190 |
| 182 private: | 191 private: |
| 183 friend class InProcessBrowserTest; | 192 friend class InProcessBrowserTest; |
| 184 | 193 |
| 185 CommandLine(); | 194 CommandLine(); |
| 186 | 195 |
| 187 // Used by InProcessBrowserTest. | 196 // Used by InProcessBrowserTest. |
| 188 static CommandLine* ForCurrentProcessMutable() { | 197 static CommandLine* ForCurrentProcessMutable() { |
| 189 DCHECK(current_process_commandline_); | 198 DCHECK(current_process_commandline_); |
| 190 return current_process_commandline_; | 199 return current_process_commandline_; |
| 191 } | 200 } |
| (...skipping 28 matching lines...) Expand all Loading... |
| 220 std::vector<StringType> args_; | 229 std::vector<StringType> args_; |
| 221 | 230 |
| 222 // We allow copy constructors, because a common pattern is to grab a | 231 // We allow copy constructors, because a common pattern is to grab a |
| 223 // copy of the current process's command line and then add some | 232 // copy of the current process's command line and then add some |
| 224 // flags to it. E.g.: | 233 // flags to it. E.g.: |
| 225 // CommandLine cl(*CommandLine::ForCurrentProcess()); | 234 // CommandLine cl(*CommandLine::ForCurrentProcess()); |
| 226 // cl.AppendSwitch(...); | 235 // cl.AppendSwitch(...); |
| 227 }; | 236 }; |
| 228 | 237 |
| 229 #endif // BASE_COMMAND_LINE_H_ | 238 #endif // BASE_COMMAND_LINE_H_ |
| OLD | NEW |