UNPKG

my-own-words

Version:

A small tool that I have created to keep safe all those words/expressions that I come across when I'm learning a new language

82 lines (77 loc) 2.19 kB
#!/usr/bin/env node const yargs = require('yargs'); const { prettyOutput } = require('./src/pretty-output'); const { newList } = require('./src/new'); const { addWord } = require('./src/add'); const { list } = require('./src/list'); const { remove } = require('./src/remove'); const { print } = require('./src/print'); const { argv } = yargs .command('new', 'Creates a new list to add vocabulary', { list: { alias: 'l', describe: 'Name of the new list', demand: true, }, }) .command( 'add', 'Add a new word and its definition to the specified list. If the word already exists, add a definition if it is not repeated', { list: { alias: 'l', describe: 'Name of the list', demand: true, }, word: { alias: 'w', describe: 'Word to add', demand: true, }, definition: { alias: 'd', describe: 'Definition of the word', demand: true, }, }, ) .command('list', 'Lists the lists or words of a list, according to the parameters received', { list: { alias: 'l', descibre: 'Name of the list', demand: false, }, }) .command('remove', 'Deletes a list, a word or a word`s definition from a list', { list: { alias: 'l', describe: 'Name of the list to remove', demand: true, }, word: { alias: 'w', describe: 'Word to remove', demand: false, }, definition: { alias: 'd', describe: 'Definition to remove', demand: false, }, }) .command('print', 'Exports the specified list in Markdown format', { list: { alias: 'l', descibre: 'Name of the list', demand: true, }, }) .help() .alias('help', 'h'); const command = argv._[0]; if (command === 'new') prettyOutput(newList(argv.list)); else if (command === 'add') addWord(argv.list, argv.word, argv.definition); else if (command === 'list') prettyOutput(list(argv.list)); else if (command === 'remove') prettyOutput(remove(argv.list, argv.word, argv.definition)); else if (command === 'print') prettyOutput(print(argv.list)); else prettyOutput('unknown command');