[go: up one dir, main page]

Menu

[c1a309]: / cli / cli.h  Maximize  Restore  History

Download this file

35 lines (31 with data), 1.3 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#ifndef CLI_H
#define CLI_H
#include <iostream>
#include <string>
#include <map>
#include <list>
#include <string.h>
#include <cstdlib>
#include "cli_version.h"
class cli_parser {
private:
std::map<std::string,std::string> optargs;
std::map<std::string,std::string> optargs_help;
std::map<std::string,bool> optswitch;
std::map<std::string,std::string> optswitch_help;
std::list<std::string> args;
std::string command;
public:
cli_parser ( std::string call ) : command ( call ) {}
void add_option ( std::string option, std::string helptext, std::string defaultvalue="" ) {
optargs[option] = defaultvalue; optargs_help[option] = helptext; }
void add_switch ( std::string option, std::string helptext, bool defaultvalue=false ) {
optswitch[option] = defaultvalue; optswitch_help[option] = helptext; }
void parse_args ( int argc, char ** argv );
std::string getOptArg ( std::string option ) { return optargs[option]; }
bool getOptSet ( std::string option ) { return optswitch[option]; }
std::string popArg ( void ) { if ( args.empty() ) return ""; std::string out ( args.front() ); args.pop_front(); return out; }
void print_help ( void );
void print_version ( void );
};
#endif