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

Add clear feature (Issue #40) #43

Merged
merged 5 commits into from
Aug 22, 2018

Conversation

JoshuaCrocker
Copy link
Contributor

Adds in functionality defined in #40, to delete all checked tasks by running a command.

This has been implemented in the tb --clean command, which will iterate through all tasks and will pass any checked tasks to the standard delete method.

screen shot 2018-08-03 at 15 49 27

Closes #40 @tmyers273

lib/help.js Outdated
@@ -19,6 +19,7 @@ module.exports = `
--priority, -p Update priority of task
--archive, -a Display archived items
--restore, -r Restore items from archive
--clean, -k Delete all checked items

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be good to keep -cl or similar like that instead of -k.

Copy link

@rjoydip-zz rjoydip-zz Aug 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, It's my bad I forgot about that meow doesn't support the multi-character

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to keep the capital C alias or revert back to k?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep as it is. Let's see what @klauscfhq thinks.

@JoshuaCrocker
Copy link
Contributor Author

Updated alias to C.

I did attempt to update it to cl as suggested, but it doesn't appear as if multi-char aliases are supported. Some further checks showed that -cl appeared to fire the list and check commands instead of the clean command.

@SakhirAtwi
Copy link

@JoshuaCrocker The library used for aliases is meow, and it doesn't allow for multi-char aliases I guess, there is some sort of glitch or something,

screenshot_20180804_140344
screenshot_20180804_140411

See?

also c flag alias has already used been used for check flag I guess so how can it be used for clean too?

@JoshuaCrocker
Copy link
Contributor Author

@SakhirAtwi The Clean command makes use of the capital C character. Meow treats the aliases as being case-sensitive so a lower case c will call the check command, but an upper case C will call the clean command.

@klaudiosinani klaudiosinani added the enhancement New feature or request label Aug 7, 2018
@klaudiosinani klaudiosinani self-requested a review August 7, 2018 16:17
cli.js Outdated
},
clean: {
type: 'boolean',
alias: 'C'
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Considering that this a console app and the fact that clear is a widely-used and familiar command among CLI users, with a closely similar effect to that of the one here, it (clear) seems to be a more appropriate flag name than clean. Also, let's completely avoid setting a shortcut/alias, in order to prevent any accidental uses.

clear: {
  type: 'boolean'
}

index.js Outdated
@@ -57,6 +57,10 @@ const taskbookCLI = (input, flags) => {
return taskbook.moveBoards(input);
}

if (flags.clean) {
return taskbook.clean();
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

lib/help.js Outdated
@@ -19,6 +19,7 @@ module.exports = `
--priority, -p Update priority of task
--archive, -a Display archived items
--restore, -r Restore items from archive
--clean, -C Delete all checked items
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--clear            Delete all checked items

lib/help.js Outdated
@@ -39,4 +40,5 @@ module.exports = `
$ tb --list pending coding
$ tb --archive
$ tb --restore 4
$ tb --clean
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$ tb --clear

lib/taskbook.js Outdated
@@ -499,6 +499,18 @@ class Taskbook {
this._save(_data);
render.successPriority(id, level);
}

clean() {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  clear() {

lib/taskbook.js Outdated
@@ -499,6 +499,18 @@ class Taskbook {
this._save(_data);
render.successPriority(id, level);
}

clean() {
const keysToDelete = [];
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make things simpler keysToDelete can be renamed to just ids and _data can be explicitly declared & pushed to the top:

const ids = [];
const {_data} = this;

lib/taskbook.js Outdated
if (item.isComplete) {
keysToDelete.push(id);
}
});
Copy link
Owner

@klaudiosinani klaudiosinani Aug 21, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Object.entries can be replaced by Object.keys so the whole method is compatible with node.js v6:

Object.keys(_data).forEach(id => {
  if (_data[id].isComplete) {
    ids.push(id);
  }
});

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes that's true

lib/taskbook.js Outdated
}
});

this.deleteItems(keysToDelete);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before calling this.deleteItems(ids) we should check if the ids array is actually empty and return if so:

if (ids.length === 0) {
  return;
}

this.deleteItems(ids);

Copy link
Owner

@klaudiosinani klaudiosinani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work! A couple of tweaks and it is good to go. Feel free to share your thoughts on the suggested changes : )

@klaudiosinani klaudiosinani merged commit e52f082 into klaudiosinani:master Aug 22, 2018
@klaudiosinani
Copy link
Owner

Thank you a lot for taking the time to contribute : )

@klaudiosinani klaudiosinani changed the title Add clean feature (Issue #40) Add clear feature (Issue #40) Oct 30, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants