-
Notifications
You must be signed in to change notification settings - Fork 29
/
wunderline-done.js
executable file
·66 lines (54 loc) · 1.48 KB
/
wunderline-done.js
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
#!/usr/bin/env node
var app = require("commander");
var async = require("async");
var fuzzysearch = require("fuzzysearch");
var inquirer = require("inquirer");
var getLists = require("./lib/get-lists");
var auth = require("./lib/auth");
var updateTask = require("./lib/update-task");
app.description("Mark a task as done").usage("[task]").parse(process.argv);
function complete(id, callback) {
updateTask(id, { completed: true }, callback);
}
function match(terms, tasks) {
return tasks.filter(function (task) {
return terms.find(function (term) {
return fuzzysearch(term.toLowerCase(), task.title.toLowerCase());
});
});
}
function main() {
getLists(function (error, lists) {
if (error) {
process.exit(1);
}
var terms = app.args;
var term = terms.join(" ");
var tasks = lists.reduce(function (registry, list) {
return registry.concat(list.tasks);
}, []);
var matches = term.length > 0 ? match([term], tasks) : tasks;
var choices = matches.map(function (match) {
return {
checked: match.completed,
value: match.id,
name: match.title,
};
});
inquirer
.prompt([
{
type: "checkbox",
name: "done",
message: "Select tasks to mark as done",
choices: choices,
},
])
.then(function (answers) {
async.eachLimit(answers.done, 10, complete, function () {
process.exit(0);
});
});
});
}
auth(main);