-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.hpp
More file actions
157 lines (144 loc) · 3.54 KB
/
Copy pathcli.hpp
File metadata and controls
157 lines (144 loc) · 3.54 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#include <iostream>
#include <string>
#include "taskManager.hpp"
using namespace std;
class CLI {
private:
int argc;
char **argv;
TaskManager Mgr;
bool isAvailable;
void help() {
cout << "Task CLI Usage:\n" << endl;
cout << "Add a new task:" << endl;
cout << " task-cli add \"Buy groceries\"" << endl;
cout << " Output: Task added successfully (ID: 1)\n" << endl;
cout << "Update a task:" << endl;
cout << " task-cli update 1 \"Buy groceries and cook dinner\"\n"
<< endl;
cout << "Delete a task:" << endl;
cout << " task-cli delete 1\n" << endl;
cout << "Mark task status:" << endl;
cout << " task-cli mark-in-progress 1" << endl;
cout << " task-cli mark-done 1\n" << endl;
cout << "List tasks:" << endl;
cout << " task-cli list\n" << endl;
cout << "List tasks by status:" << endl;
cout << " task-cli list done" << endl;
cout << " task-cli list todo" << endl;
cout << " task-cli list in-progress\n" << endl;
cout << "Available Commands:" << endl;
cout << " add" << endl;
cout << " update" << endl;
cout << " delete" << endl;
cout << " mark-in-progress" << endl;
cout << " mark-done" << endl;
cout << " list" << endl;
cout << " help" << endl;
}
public:
CLI(int argc,char **argv){
if(argc < 2){
help();
isAvailable = false;
return;
}
this->argc = argc;
this->argv = argv;
isAvailable = true;
}
bool isTrue(){
return this->isAvailable;
}
void processArgs(){
if (argc < 2){
help();
}
string cmd = argv[1];
if(cmd == "help"){
help();
}else if(cmd == "add"){
if (argc < 3 ){
cout << " Usage: ./cli add \"Buy groceries\"" << endl;
return;
}
if (handleAdd(argv[2]) == -1){
cout<<"Failed To Add Task!!!"<<endl;
}else{
cout<<"Task added successfully"<<endl;
}
}else if(cmd == "delete"){
if (argc < 3){
cout << "Usage: ./cli delete 1" << endl;
return;
}
if (handleDelete((atoi)(argv[2])) == -1){
cout<<"Failed To Delete Task!!!"<<endl;
}else{
cout<<"Task deleted successfully"<<endl;
}
}else if(cmd == "update"){
if (argc < 4){
cout << "Usage: ./cli update <id> <description>" << endl;
return;
}
if (handleUpdate((atoi)(argv[2]),argv[3]) == -1){
cout<<"Failed To Update Task!!!"<<endl;
}else{
cout<<"Task updated successfully"<<endl;
}
}else if(cmd == "list"){
if (argc < 3){
handleList();
}else{
if (argv[2] == "done"){
handleListDone();
}else if (argv[2] == "todo"){
handleListToDo();
}else if(argv[2] == "in-progress"){
handleListInProgress();
}else{
cout<<"Invalid status!!!"<<endl;
help();
}
}
}else if(cmd == "mark-in-progress"){
if (handleMarkInProgress((atoi)(argv[2])) == -1){
cout<<"Failed To Mark-In-Progress!!!"<<endl;
}
}else if(cmd == "mark-done"){
if (handleMarkDone((atoi)(argv[2])) == -1){
cout<<"Failed To Mark-Done!!!"<<endl;
}
}else{
help();
}
}
int handleAdd(string desc){
return Mgr.Add(desc);
}
int handleDelete(int id){
return Mgr.Delete(id);
}
int handleUpdate(int id,string desc){
return Mgr.Update(id,desc);
}
int handleMarkInProgress(int id){
return Mgr.MarkInProgress(id);
}
int handleMarkDone(int id){
return Mgr.MarkDone(id);
}
void handleList(){
Mgr.List();
}
void handleListDone(){
Mgr.ListDone();
}
void handleListToDo(){
Mgr.ListToDo();
}
void handleListInProgress(){
Mgr.ListInProgress();
}
};