| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 // Provides a simple class, |CommandLine|, for dealing with command lines (and | 5 // Provides a simple class, |CommandLine|, for dealing with command lines (and |
| 6 // flags and positional arguments). | 6 // flags and positional arguments). |
| 7 // | 7 // |
| 8 // * Options (a.k.a. flags or switches) are all of the form "--name=<value>" (or | 8 // * Options (a.k.a. flags or switches) are all of the form "--name=<value>" (or |
| 9 // "--name", but this is indistinguishable from "--name="), where <value> is a | 9 // "--name", but this is indistinguishable from "--name="), where <value> is a |
| 10 // string. Not supported: "-name", "-n", "--name <value>", "-n <value>", etc. | 10 // string. Not supported: "-name", "-n", "--name <value>", "-n <value>", etc. |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 #include "mojo/public/cpp/system/macros.h" | 45 #include "mojo/public/cpp/system/macros.h" |
| 46 | 46 |
| 47 namespace mojo { | 47 namespace mojo { |
| 48 namespace util { | 48 namespace util { |
| 49 | 49 |
| 50 // CommandLine ----------------------------------------------------------------- | 50 // CommandLine ----------------------------------------------------------------- |
| 51 | 51 |
| 52 // Class that stores processed command lines ("argv[0]", options, and positional | 52 // Class that stores processed command lines ("argv[0]", options, and positional |
| 53 // arguments) and provides access to them. For more details, see the file-level | 53 // arguments) and provides access to them. For more details, see the file-level |
| 54 // comment above. This class is thread-safe. | 54 // comment above. This class is thread-safe. |
| 55 class CommandLine { | 55 class CommandLine final { |
| 56 private: | 56 private: |
| 57 class ConstructionHelper; | 57 class ConstructionHelper; |
| 58 | 58 |
| 59 public: | 59 public: |
| 60 struct Option { | 60 struct Option { |
| 61 Option() {} | 61 Option() {} |
| 62 explicit Option(const std::string& name); | 62 explicit Option(const std::string& name); |
| 63 Option(const std::string& name, const std::string& value); | 63 Option(const std::string& name, const std::string& value); |
| 64 | 64 |
| 65 bool operator==(const Option& other) const { | 65 bool operator==(const Option& other) const { |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 | 132 |
| 133 // Allow copy and assignment. | 133 // Allow copy and assignment. |
| 134 }; | 134 }; |
| 135 | 135 |
| 136 // Factory functions (etc.) ---------------------------------------------------- | 136 // Factory functions (etc.) ---------------------------------------------------- |
| 137 | 137 |
| 138 namespace internal { | 138 namespace internal { |
| 139 | 139 |
| 140 // Helper class for building command lines (finding options, etc.) from raw | 140 // Helper class for building command lines (finding options, etc.) from raw |
| 141 // arguments. | 141 // arguments. |
| 142 class CommandLineBuilder { | 142 class CommandLineBuilder final { |
| 143 public: | 143 public: |
| 144 CommandLineBuilder(); | 144 CommandLineBuilder(); |
| 145 ~CommandLineBuilder(); | 145 ~CommandLineBuilder(); |
| 146 | 146 |
| 147 // Processes an additional argument in the command line. Returns true if |arg| | 147 // Processes an additional argument in the command line. Returns true if |arg| |
| 148 // is the *first* positional argument. | 148 // is the *first* positional argument. |
| 149 bool ProcessArg(const std::string& arg); | 149 bool ProcessArg(const std::string& arg); |
| 150 | 150 |
| 151 // Builds a |CommandLine| from the arguments processed so far. | 151 // Builds a |CommandLine| from the arguments processed so far. |
| 152 CommandLine Build() const; | 152 CommandLine Build() const; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 | 215 |
| 216 // This is the "opposite" of the above factory functions, transforming a | 216 // This is the "opposite" of the above factory functions, transforming a |
| 217 // |CommandLine| into a vector of argument strings according to the rules | 217 // |CommandLine| into a vector of argument strings according to the rules |
| 218 // outlined at the top of this file. | 218 // outlined at the top of this file. |
| 219 std::vector<std::string> CommandLineToArgv(const CommandLine& command_line); | 219 std::vector<std::string> CommandLineToArgv(const CommandLine& command_line); |
| 220 | 220 |
| 221 } // namespace util | 221 } // namespace util |
| 222 } // namespace mojo | 222 } // namespace mojo |
| 223 | 223 |
| 224 #endif // MOJO_EDK_UTIL_COMMAND_LINE_H_ | 224 #endif // MOJO_EDK_UTIL_COMMAND_LINE_H_ |
| OLD | NEW |