Skip to content

Instantly share code, notes, and snippets.

@ZeroX-DG
Created June 24, 2018 04:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ZeroX-DG/4df86a094616c0ab10bf5682415cd104 to your computer and use it in GitHub Desktop.
Save ZeroX-DG/4df86a094616c0ab10bf5682415cd104 to your computer and use it in GitHub Desktop.
import {Command} from '@oclif/command'
import * as inquirer from 'inquirer'
import todoAPI from '../api/todoAPI'
export default class Interact extends Command {
static description = 'Enter the interacting mode'
async run() {
const source = todoAPI.list()
const choices = source // make a copy of the source
const prompt : any = await inquirer.prompt([
{
type: 'checkbox',
message: 'Update todo',
name: 'todos',
choices: choices.map(todo => {
// the default checked value is determined by the status of todo
return { name: todo.todo, checked: todo.done }
})
}
])
const finishedTodo = prompt.todos // list of todos selected by user
source.forEach((todo, index) => {
if (finishedTodo.indexOf(todo.todo) !== -1) {
// the todo is in the select list
todoAPI.done(index)
} else {
// the todo is not in the select list
todoAPI.undone(index)
}
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment