This repository has been archived by the owner on Nov 9, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patht.cpp
54 lines (50 loc) · 1.86 KB
/
t.cpp
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
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <cstdlib>
#include "TodoList.hpp"
int main(int argc, char* argv[]) {
TodoList tl;
std::vector<std::string> args(argv, argv+argc);
if (argc == 1) {
// Called as 't'. Dump the todo list.
tl.dump();
} else {
if (args[1] == "-h") {
// Called as 't -h': Dump some help info.
std::cout << "usage: t # Dump all items." << std::endl;
std::cout << " t 3 # Erase the third item." << std::endl;
std::cout << " t Walk the dog # Add an item." << std::endl;
std::cout << " t -e # Open todo.txt in $EDITOR." << std::endl;
std::cout << " t -h # Show this help text." << std::endl;
std::cout << " t -c # Count the amount of items." << std::endl;
std::cout << " t -r # Reorder the items." << std::endl;
std::cout << std::endl;
exit(0);
} else if (args[1] == "-e") {
// Called as 't -e'. Open todo.txt in $EDITOR.
tl.edit();
} else if (args[1] == "-c") {
// Called as 't -c'. Count the amount of items in the list.
std::cout << tl.count() << std::endl;
} else if (args[1] == "-r") {
// Called as 't -r'. Reorder the items.
tl.reorder();
} else if (atoi(argv[1]) != 0) {
// Called as 't 3' or similar. Erase the task.
tl.erase(atoi(argv[1]));
} else if (args[1].find_first_not_of("1234567890. ") == std::string::npos) {
std::cout << "Say what?" << std::endl;
} else {
// Called as 't Walk the dog' or similar.
// Collect the argument:
std::ostringstream oss;
for (std::vector<std::string>::iterator it = args.begin()+1; it < args.end()-1; ++it) {
oss << *it << " ";
}
oss << args.back();
tl.add(oss.str());
}
}
}