summaryrefslogtreecommitdiff
path: root/got.cpp
diff options
context:
space:
mode:
authorTom Smeding <tom.smeding@gmail.com>2020-04-02 16:06:35 +0200
committerTom Smeding <tom.smeding@gmail.com>2020-04-02 16:06:35 +0200
commitc66b8ded10f0d5e872e507fdff3010f732aa5449 (patch)
tree53b728799b2d1c0ad0d7027f9b816faf12591e58 /got.cpp
parent624effabd4a3be9894ffca29b9bd43868d739f3c (diff)
Split main.cpp into separate files
Diffstat (limited to 'got.cpp')
-rw-r--r--got.cpp45
1 files changed, 45 insertions, 0 deletions
diff --git a/got.cpp b/got.cpp
new file mode 100644
index 0000000..e60b4c6
--- /dev/null
+++ b/got.cpp
@@ -0,0 +1,45 @@
+#include <sstream>
+#include <algorithm>
+#include "command.h"
+#include "got.h"
+#include "sqliteutil.h"
+
+
+namespace got {
+ std::string getDBpath() {
+ return std::string{getenv("HOME")} + "/.timetrap.db";
+ }
+
+ // Returns {sheet, note}
+ std::optional<std::pair<std::string, std::string>> getRunning() {
+ std::string output = runCommand({"sqlite3", getDBpath(), ".mode csv", "select sheet, note from entries where end is null"});
+ auto table = sqlite::parseCSV(move(output));
+ if (table.empty()) return std::nullopt;
+ else return std::make_pair(table[0][0], table[0][1]);
+ }
+
+ std::vector<std::string> getSheets() {
+ std::string output = runCommand({"sqlite3", getDBpath(), "select distinct sheet from entries"});
+ std::istringstream ss{output};
+ std::vector<std::string> lines;
+ std::string line;
+ while (std::getline(ss, line)) {
+ if (line.size() > 0) lines.push_back(move(line));
+ }
+ std::sort(lines.begin(), lines.end());
+ return lines;
+ }
+
+ void editRunning(const std::string &descr) {
+ runCommand({"got", "edit", descr});
+ }
+
+ void checkOut() {
+ runCommand({"got", "out"});
+ }
+
+ void checkIn(const std::string &sheet) {
+ runCommand({"got", "sheet", sheet});
+ runCommand({"got", "in"});
+ }
+}