forked from nodegit/nodegit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcmd.h
More file actions
56 lines (49 loc) · 1.65 KB
/
cmd.h
File metadata and controls
56 lines (49 loc) · 1.65 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#ifndef NODEGIT_CMD_H
#define NODEGIT_CMD_H
#include <string>
#include <map>
namespace nodegit {
/**
* \class Cmd
* Abstract class holding a command to execute.
*
* Instances of Cmd will store all the information needed to run the command,
* including environment variables to set, like CWD.
*/
class Cmd {
public:
/* Enumeration describing the environment variables that Cmd will handle
* - kCWD: Current Working Directory.
*/
enum class Env {kCWD};
Cmd() = default;
virtual ~Cmd() = default;
Cmd(const Cmd &other) = delete;
Cmd(Cmd &&other) = delete;
Cmd& operator=(const Cmd &other) = delete;
Cmd& operator=(Cmd &&other) = delete;
virtual std::string Command() const = 0; // return the command to execute
virtual std::string Args() const = 0; // return the arguments of the command if any
void SetEnv(Env env, const std::string &value) {
m_env[env] = value;
}
std::string GetEnv(Env env) const {
auto value = m_env.find(env);
if (value != m_env.end()) { return value->second; }
else { return std::string(""); }
}
void SetRedirectStdErr(bool redirectStdErr) {
m_redirectStdErr = redirectStdErr;
}
bool GetRedirectStdErr() const {
return m_redirectStdErr;
}
// TODO: turn private, and restrict set/get access with pre-validation if necessary
std::string out {}; // cmd output. TODO: stream here?
std::string errorMsg {}; // error message if the command execution failed
private:
std::map<Env, std::string> m_env {}; // environment variables for this command
bool m_redirectStdErr {true}; // whether or not to redirect stderr to stdout
};
} // namespace nodegit
#endif // NODEGIT_CMD_H