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