shahednasser / todos-cli

29 stars 2 forks source link

Where is the task list we created or how to clean up the task lists #1

Open twocoins-ca opened 1 year ago

twocoins-ca commented 1 year ago

Thanks for your post and how do we clean up the task lists or it must be store in our local files somewhere?

PavelNaydanov commented 1 year ago

Thanks for your post and how do we clean up the task lists or it must be store in our local files somewhere?

  1. You need to add new program for clear tasks. It's the same another programs.
program
  .command('clear')
  .description('Clear tasks')
  .option('-t, --tasks <tasks...>', 'The tasks to clear. If not specified, all tasks will be cleared.')
  .action(clear)
  1. You need add new clear.js in commands folder.
export function clear({tasks}) {
  let todoList = conf.get('todo-list');

  if (todoList) {
    if (tasks) {
      tasks.forEach(task => {
        const index = todoList.indexOf(task);

        if (index != -1) {
          todoList.splice(index, 1);
        } else {
          console.log(chalk.red.bold(`Task ${task} not found`));
          process.exit();
        }
      });
    } else {
      todoList = [];
    }

    conf.set('todo-list', todoList);
  }

  console.log(chalk.green.bold('Task has been cleared successfully!'));
}