-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcommands.h
38 lines (33 loc) · 1.01 KB
/
commands.h
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
35
36
37
38
#ifndef commands_H
#define commands_H
#include <string>
#include <iostream>
#include <set>
//----------
//
// Command class--
// Subclasses should override everything here, except (usually) the destructor
// and main().
//
//----------
class Command
{
public:
Command(const std::string& name) { commandName = name; }
virtual ~Command() {}
virtual int main (int argc, char** argv)
{ parse (argc, argv); return execute (); }
virtual void chastise (const std::string& message = "")
{ usage (std::cerr, message); std::exit (EXIT_FAILURE); }
virtual void short_description (std::ostream& s) {}
virtual void usage (std::ostream& s, const std::string& message = "") {}
virtual void debug_help (std::ostream& s) {}
virtual void parse (int _argc, char** _argv) {}
virtual bool in_debug(std::string keyword) { return contains(debug,keyword); }
virtual int execute (void) { return 0; }
public:
std::string commandName;
std::set<std::string> debug;
std::vector<std::string> deferredCommands;
};
#endif // commands_H