Skip to content

Commit e52f082

Browse files
JoshuaCrockerklaudiosinani
authored andcommitted
Added option to clear complete tasks. Fixes #40. (#43)
* Add clean feature * Changed clean alias to 'C' (Cap-C) * @klauscfhq Review Changes * Fix formatting issues
1 parent 4ef7d20 commit e52f082

File tree

4 files changed

+26
-0
lines changed

4 files changed

+26
-0
lines changed

cli.js

100644100755
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ const cli = meow(help, {
6767
move: {
6868
type: 'boolean',
6969
alias: 'm'
70+
},
71+
clear: {
72+
type: 'boolean'
7073
}
7174
}
7275
});

index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ const taskbookCLI = (input, flags) => {
5757
return taskbook.moveBoards(input);
5858
}
5959

60+
if (flags.clear) {
61+
return taskbook.clear();
62+
}
63+
6064
taskbook.displayByBoard();
6165
return taskbook.displayStats();
6266
};

lib/help.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ module.exports = `
1919
--priority, -p Update priority of task
2020
--archive, -a Display archived items
2121
--restore, -r Restore items from archive
22+
--clear Delete all checked items
2223
--help, -h Display help message
2324
--version, -v Display installed version
2425
@@ -39,4 +40,5 @@ module.exports = `
3940
$ tb --list pending coding
4041
$ tb --archive
4142
$ tb --restore 4
43+
$ tb --clear
4244
`;

lib/taskbook.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,23 @@ class Taskbook {
502502
this._save(_data);
503503
render.successPriority(id, level);
504504
}
505+
506+
clear() {
507+
const ids = [];
508+
const {_data} = this;
509+
510+
Object.keys(_data).forEach(id => {
511+
if (_data[id].isComplete) {
512+
ids.push(id);
513+
}
514+
});
515+
516+
if (ids.length === 0) {
517+
return;
518+
}
519+
520+
this.deleteItems(ids);
521+
}
505522
}
506523

507524
module.exports = new Taskbook();

0 commit comments

Comments
 (0)