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