Vishwanatha Subbanna | 15b1dc1 | 2017-05-23 15:16:13 +0530 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <getopt.h> |
| 4 | #include <map> |
| 5 | #include <string> |
William A. Kennington III | 5d30718 | 2018-01-23 22:00:55 -0800 | [diff] [blame] | 6 | #include <vector> |
Vishwanatha Subbanna | 15b1dc1 | 2017-05-23 15:16:13 +0530 | [diff] [blame] | 7 | |
| 8 | namespace phosphor |
| 9 | { |
| 10 | namespace watchdog |
| 11 | { |
| 12 | /** @brief Class ArgumentParser - Encapsulates parsing command line options |
| 13 | * and populating arguments |
| 14 | */ |
| 15 | class ArgumentParser |
| 16 | { |
| 17 | public: |
| 18 | ArgumentParser() = delete; |
| 19 | ~ArgumentParser() = default; |
| 20 | ArgumentParser(const ArgumentParser&) = delete; |
| 21 | ArgumentParser& operator=(const ArgumentParser&) = delete; |
| 22 | ArgumentParser(ArgumentParser&&) = default; |
| 23 | ArgumentParser& operator=(ArgumentParser&&) = default; |
| 24 | |
| 25 | /** @brief Contructs ArgumentParser object |
| 26 | * |
| 27 | * @param argc - the main function's argc passed as is |
| 28 | * @param argv - the main function's argv passed as is |
| 29 | * @return Object constructed |
| 30 | */ |
William A. Kennington III | 6c094a2 | 2018-01-29 12:09:29 -0800 | [diff] [blame] | 31 | ArgumentParser(int argc, char * const argv[]); |
Vishwanatha Subbanna | 15b1dc1 | 2017-05-23 15:16:13 +0530 | [diff] [blame] | 32 | |
| 33 | /** @brief Given an option, returns its argument(optarg) |
| 34 | * |
| 35 | * @param opt - command line option string |
| 36 | * |
| 37 | * @return argument which is a standard optarg |
| 38 | */ |
William A. Kennington III | 5d30718 | 2018-01-23 22:00:55 -0800 | [diff] [blame] | 39 | const std::vector<std::string>& operator[](const std::string& opt); |
Vishwanatha Subbanna | 15b1dc1 | 2017-05-23 15:16:13 +0530 | [diff] [blame] | 40 | |
| 41 | /** @brief Displays usage |
| 42 | * |
| 43 | * @param argv - the main function's argv passed as is |
| 44 | */ |
William A. Kennington III | 6c094a2 | 2018-01-29 12:09:29 -0800 | [diff] [blame] | 45 | static void usage(char * const argv[]); |
Vishwanatha Subbanna | 15b1dc1 | 2017-05-23 15:16:13 +0530 | [diff] [blame] | 46 | |
| 47 | /** @brief Set to 'true' when an option is passed */ |
| 48 | static const std::string trueString; |
| 49 | |
Vishwanatha Subbanna | 15b1dc1 | 2017-05-23 15:16:13 +0530 | [diff] [blame] | 50 | private: |
| 51 | /** @brief Option to argument mapping */ |
William A. Kennington III | 5d30718 | 2018-01-23 22:00:55 -0800 | [diff] [blame] | 52 | std::map<const std::string, std::vector<std::string> > arguments; |
Vishwanatha Subbanna | 15b1dc1 | 2017-05-23 15:16:13 +0530 | [diff] [blame] | 53 | |
| 54 | /** @brief Array of struct options as needed by getopt_long */ |
| 55 | static const option options[]; |
| 56 | |
| 57 | /** @brief optstring as needed by getopt_long */ |
| 58 | static const char* optionStr; |
| 59 | }; |
| 60 | |
| 61 | } // namespace watchdog |
| 62 | } // namespace phosphor |