Repository navigation
Expand file tree
/
Copy pathcli.js
More file actions
executable file
·181 lines (159 loc) · 4.81 KB
/
Copy pathcli.js
File metadata and controls
executable file
·181 lines (159 loc) · 4.81 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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#!/usr/bin/env node
const ff = require("./index.js");
const commander = require("commander");
const os = require("os");
const {
execDaemonOption,
exportOption,
deleteOption,
editOption,
setnotifyOption,
categorizeOption,
priorityOption,
urgencyOption,
dueOption,
readOption,
removenoteOption,
noteOption,
markCompletedOption,
replaceOption,
appendOption,
addOption,
isExists } = require("./src/utils.js");
const pkgJson = require("./package.json");
commander
.version(pkgJson.version)
.command("add <todo> [category...]")
.description("Add todo into category, category is optional")
.action((todo, category) => {
return addOption(todo, category, ff);
});
commander
.command("append <hash> <text>")
.description("Append text into todo with the id of hash")
.action((hash, text) => {
return appendOption(hash, text, ff);
});
commander
.command("replace <hash> <regexp> <text>")
.description("replace a text speicified by regexp with text into todo with id of hash")
.action((hash, regexp, text) => {
return replaceOption(hash, regexp, text, ff);
});
commander
.command("markcompleted <hash>")
.description("mark a todo with the id of hash completed")
.action(hash => {
// return ff.markcompleted({hash});
return markCompletedOption(hash, ff);
});
commander
.command("note <hash> <note>")
.description("add a little note in a todo with id of hash")
.action((hash, note) => {
return noteOption(hash, note, ff);
});
commander
.command("removenote <hash>")
.description("remove note that has been added to todo with the id of hash")
.action(hash => {
return removenoteOption(hash);
});
commander
.command("read <type>")
.description(`read the todo that meets the type criteria
valid types are all , date , completed, notcompleted, due , category, urgency, eval`)
.option("--date <date> specifiy date to use")
.option("--modifiedDate <date> specifiy a modified date to search with")
.action((type, options) => {
const { date, modifiedDate } = options;
if (date && !modifiedDate) {
return readOption(type, { date }, ff);
} else if (!date && modifiedDate) {
return readOption(type, {modifiedDate}, ff);
} else if (date && modifiedDate) {
return readOption(type, {date, modifiedDate}, ff);
} else {
return readOption(type, undefined, ff);
}
});
commander
.command("delete <type>")
.description(`delete any todo that meets the type criteria
valid types are all , hash, completed, date, category, `)
.action(type => {
let argumentArray;
const [ _type, value ] = argumentArray = type.split(":");
if (/^all$|^completed$/.test(_type)) {
return deleteOption(_type, undefined, ff);
} else {
return deleteOption(_type, { value }, ff);
}
});
commander
.command("urgency <hash> <urgency>")
.description(`specify how urgent you want to accomplish this task
valid urgency types are pending,waiting,later,tomorrow,today`)
.action((hash, urgency) => {
return urgencyOption(hash, urgency, ff);
});
commander
.command("priority <hash> <priority>")
.description(`specify the task priority
valid priorities are critical and notcritical`)
.action((hash, priority) => {
return priorityOption(hash, priority, ff);
});
commander
.command("categorize <hash> [category...]")
.description("add a todo to a particular category")
.action((hash, category) => {
return categorizeOption(hash, category, ff);
});
commander
.command("due <hash> <date>")
.description("set the date in which hash is due")
.action((hash, date) => {
return dueOption(hash, date, ff);
});
commander
.command("export <type> <path>")
.description(`export todo as type to path
valid export types are xml,html,json`)
.action((type, path) => {
return exportOption(type, path, ff);
});
commander
.command("set_notify <hash> <notification> <timeout> ")
.description("set notification option for a particular todo")
.action((hash, notification, timeout) => {
return setnotifyOption(hash, notification, timeout, ff);
});
commander
.command("help")
.description("show help commands for duty")
.action(_ => {
commander.outputHelp();
});
commander
.command("daemon")
.description("use to make duty run in background, executing this subcommand from the commandline won't work")
.action(_ => {
ff.daemon();
});
commander
.command("create-service")
.description("creates a service file to handle daemons for background notification")
.action(() => {
execDaemonOption(os.platform,ff);
});
commander
.command("edit <hash> <text>")
.description("this subcommand edits a todo")
.action((hash, text) => {
return editOption(hash, text, ff);
});
commander.parse(process.argv);
if (!process.argv.slice(2).length) {
isExists("/config.json", commander);
}