Created
June 24, 2018 04:58
-
-
Save ZeroX-DG/4df86a094616c0ab10bf5682415cd104 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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