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