]> git.armaanb.net Git - gen-shell.git/blob - src/sarge.h
Major restructuring
[gen-shell.git] / src / sarge.h
1 /*
2         sarge.h - Header file for the Sarge command line argument parser project.
3         
4         Revision 0
5         
6         Notes:
7                         -
8                          
9         2019/03/16, Maya Posch
10         
11 */
12
13
14 #include <string>
15 #include <vector>
16 #include <map>
17 #include <memory>
18
19
20 struct Argument {
21         Argument() : hasValue(false), parsed(false) { /* */ }
22         std::string arg_short;
23         std::string arg_long;
24         std::string description;
25         bool hasValue;
26         std::string value;
27         bool parsed;
28 };
29
30
31
32 class Sarge {
33         std::vector<std::unique_ptr<Argument> > args;
34         std::map<std::string, Argument*> argNames;
35         bool parsed = false;
36         int flagCounter = 0;
37         std::string execName;
38         std::string description;
39         std::string usage;
40         std::vector<std::string> textArguments;
41         
42 public:
43         void setArgument(std::string arg_short, std::string arg_long, std::string desc, bool hasVal);
44         void setArguments(std::vector<Argument> args);
45         void setDescription(std::string desc) { this->description = desc; }
46         void setUsage(std::string use) { this->usage = use; }
47         bool parseArguments(int argc, char** argv);
48         bool getFlag(std::string arg_flag, std::string &arg_value);
49         bool exists(std::string arg_flag);
50         bool getTextArgument(uint32_t index, std::string &value);
51         void printHelp();
52         int flagCount() { return flagCounter; }
53         std::string executableName() { return execName; }
54 };