In my API library (C++) I am wrapping a shell process (spawned using popen) with several classes to manipulate a file system.
The base class
ProcessFileWrap wraps general filesystem tasks and executes other custom tasks from its derived classes. It looks like below in pseudocode:
// ProcessFileWrap base class methods ExecCustomProcess(string process) // does popen(process, "r") ChangeDir(string path) // changes the current directory AddFolder(string path) // wrapper for mkdir AddFile(string path) // wrapper for touch MakeLink(string pathToFile, string pathToLink) // wrapper for ln -s // ... And so on
There are several derived classes. One of them is
GitFileWrap, which wraps git processes like so (again in psuedocode). It needs to do some specific file system tasks after or during the process:
// GitFileWrap derived class methods // Calls ChangeDir(pathToRepo) and ExecCustomProcess("git pull") // Afterwards it creates links for each pulled file in a custom // directory via MakeLink(file, customLoc). Pull() // Calls ExecCustomProcess(git commit -m obj.GetCommitMessage()) // A GitObject represents a git versioned object in the filesystem. Commit(GitObject obj) // ... And so on
So users of the API would call methods from the derived classes as needed.
I am aware that wrapping processes is in general not best practice, so if you can, please comment on the design with the assumption that there isn't really another alternative (or I guess you could, but I would appreciate comments on the design above). Thanks!
Note: It is not possible for me to use libgit2