Matt Spinler | 389ca67 | 2017-05-09 10:50:28 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <getopt.h> |
Matthew Barth | 9e80c87 | 2020-05-26 10:50:29 -0500 | [diff] [blame] | 4 | |
Matt Spinler | 389ca67 | 2017-05-09 10:50:28 -0500 | [diff] [blame] | 5 | #include <map> |
| 6 | #include <string> |
| 7 | |
| 8 | namespace phosphor |
| 9 | { |
| 10 | namespace fan |
| 11 | { |
| 12 | namespace util |
| 13 | { |
| 14 | |
| 15 | /** |
| 16 | * Parses command line arguments. |
| 17 | * This header can be used by all fan applications, while |
| 18 | * the .cpp will need to be implemented by each of them. |
| 19 | */ |
| 20 | class ArgumentParser |
| 21 | { |
Matthew Barth | 9e80c87 | 2020-05-26 10:50:29 -0500 | [diff] [blame] | 22 | public: |
| 23 | ArgumentParser(int argc, char** argv); |
| 24 | ArgumentParser() = delete; |
| 25 | ArgumentParser(const ArgumentParser&) = delete; |
| 26 | ArgumentParser(ArgumentParser&&) = default; |
| 27 | ArgumentParser& operator=(const ArgumentParser&) = delete; |
| 28 | ArgumentParser& operator=(ArgumentParser&&) = default; |
| 29 | ~ArgumentParser() = default; |
| 30 | const std::string& operator[](const std::string& opt); |
Matt Spinler | 389ca67 | 2017-05-09 10:50:28 -0500 | [diff] [blame] | 31 | |
Matthew Barth | 9e80c87 | 2020-05-26 10:50:29 -0500 | [diff] [blame] | 32 | static void usage(char** argv); |
Matt Spinler | 389ca67 | 2017-05-09 10:50:28 -0500 | [diff] [blame] | 33 | |
Matthew Barth | 9e80c87 | 2020-05-26 10:50:29 -0500 | [diff] [blame] | 34 | static const std::string true_string; |
| 35 | static const std::string empty_string; |
Matt Spinler | 389ca67 | 2017-05-09 10:50:28 -0500 | [diff] [blame] | 36 | |
Matthew Barth | 9e80c87 | 2020-05-26 10:50:29 -0500 | [diff] [blame] | 37 | private: |
| 38 | std::map<const std::string, std::string> arguments; |
Matt Spinler | 389ca67 | 2017-05-09 10:50:28 -0500 | [diff] [blame] | 39 | |
Matthew Barth | 9e80c87 | 2020-05-26 10:50:29 -0500 | [diff] [blame] | 40 | static const option options[]; |
| 41 | static const char* optionstr; |
Matt Spinler | 389ca67 | 2017-05-09 10:50:28 -0500 | [diff] [blame] | 42 | }; |
| 43 | |
Matthew Barth | 9e80c87 | 2020-05-26 10:50:29 -0500 | [diff] [blame] | 44 | } // namespace util |
| 45 | } // namespace fan |
| 46 | } // namespace phosphor |