Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: added purge function to clean archive and reset numbering #195

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ const cli = meow(help, {
},
clear: {
type: 'boolean'
},
purge:{
type: 'boolean'
}
}
});
Expand Down
4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ const taskbookCLI = (input, flags) => {
return taskbook.clear();
}

if (flags.purge) {
return taskbook.purge();
}

taskbook.displayByBoard();
return taskbook.displayStats();
};
Expand Down
2 changes: 2 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,15 @@ $ tb --help
--task, -t Create task
--timeline, -i Display timeline view
--version, -v Display installed version
--purge Purge the archive and reset the ids

Examples
$ tb
$ tb --archive
$ tb --begin 2 3
$ tb --check 1 2
$ tb --clear
$ tb --purge
$ tb --copy 1 2 3
$ tb --delete 4
$ tb --edit @3 Merge PR #42
Expand Down
2 changes: 2 additions & 0 deletions src/help.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@ module.exports = `
--task, -t Create task
--timeline, -i Display timeline view
--version, -v Display installed version
--purge Purge the archive and reset the ids

Examples
$ tb
$ tb --archive
$ tb --begin 2 3
$ tb --check 1 2
$ tb --clear
$ tb --purge
$ tb --copy 1 2 3
$ tb --delete 4
$ tb --edit @3 Merge PR #42
Expand Down
7 changes: 7 additions & 0 deletions src/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,13 @@ class Render {
success({prefix, message, suffix});
}

successPurged(count) {
const prefix = '\n';
const suffix = count > 1 ? 'items' : 'item';
const message = `Purged ${count}`;
success({prefix, message, suffix});
}

successMove(id, boards) {
const [prefix, suffix] = ['\n', grey(boards.join(', '))];
const message = `Move item: ${grey(id)} to`;
Expand Down
27 changes: 27 additions & 0 deletions src/taskbook.js
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,33 @@ class Taskbook {

this.deleteItems(ids);
}

purge() {
const {_archive} = this;
const ids_archive = Object.keys(_archive)
const {_data} = this;

// Remove ids in Archive
this._saveArchive({});

// Update ids in storage
const ids = Object.keys(_data)

const new_data = {}

for (let i = 0; i < ids.length; i++){
const item = _data[ids[i]];
delete _data[ids[i]];

item._id = i
new_data[i] = item;
}

// Save Data
this._save(new_data);

render.successPurged(ids_archive.length);
}
}

module.exports = new Taskbook();