1+ #ifndef NODEGIT_CMD_H
2+ #define NODEGIT_CMD_H
3+
4+ #include < string>
5+ #include < map>
6+
7+ namespace nodegit {
8+ /* *
9+ * \class Cmd
10+ * Abstract class holding a command to execute.
11+ *
12+ * Instances of Cmd will store all the information needed to run the command,
13+ * including environment variables to set, like CWD.
14+ */
15+ class Cmd {
16+ public:
17+ /* Enumeration describing the environment variables that Cmd will handle
18+ * - kCWD: Current Working Directory.
19+ */
20+ enum class Env {kCWD };
21+
22+ Cmd () = default ;
23+ virtual ~Cmd () = default ;
24+ Cmd (const Cmd &other) = delete ;
25+ Cmd (Cmd &&other) = delete ;
26+ Cmd& operator =(const Cmd &other) = delete ;
27+ Cmd& operator =(Cmd &&other) = delete ;
28+
29+ virtual std::string Command () const = 0; // return the command to execute
30+ virtual std::string Args () const = 0; // return the arguments of the command if any
31+
32+ void SetEnv (Env env, const std::string &value) {
33+ m_env[env] = value;
34+ }
35+ std::string GetEnv (Env env) const {
36+ auto value = m_env.find (env);
37+ if (value != m_env.end ()) { return value->second ; }
38+ else { return std::string (" " ); }
39+ }
40+ void SetRedirectStdErr (bool redirectStdErr) {
41+ m_redirectStdErr = redirectStdErr;
42+ }
43+ bool GetRedirectStdErr () const {
44+ return m_redirectStdErr;
45+ }
46+
47+ // TODO: turn private, and restrict set/get access with pre-validation if necessary
48+ std::string out {}; // cmd output. TODO: stream here?
49+ std::string errorMsg {}; // error message if the command execution failed
50+
51+ private:
52+ std::map<Env, std::string> m_env {}; // environment variables for this command
53+ bool m_redirectStdErr {true }; // whether or not to redirect stderr to stdout
54+ };
55+ } // namespace nodegit
56+ #endif // NODEGIT_CMD_H
0 commit comments