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