blob: c314006c1fde3c45b37afc3739de48dcf74b14cf [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
33 static constexpr auto true_string = "true";
34 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}