UNPKG

@gameroom/cli

Version:

A command line tool for Gameroom

33 lines (28 loc) 1.16 kB
const pluralize = require('pluralize'), { models: { Selection } } = require('../emporium'), { getStorable, grGreen } = require('../helpers'), { spinner } = require('../refs') module.exports = async ({ resource }) => { if (pluralize.isPlural(resource)) resource = pluralize.singular(resource) spinner.text = `deselecting ${grGreen(resource)}` spinner.start() if (resource === 'all') { const selections = await Selection.get({sort: { resource: 1 } }) if (selections.length === 0) return spinner.fail('nothing selected') for (const selection of selections) { await selection.delete() spinner.info(`deselected ${grGreen(selection.resource)} ${selection.object.id}`) } spinner.succeed('deselected all').stop() return } const Model = getStorable(resource) if (!Model) throw new Error(`unrecognized resource ${grGreen(resource)}`) const selection = await Selection.find(resource) if (selection) { await selection.delete() spinner.succeed(`deselected ${grGreen(selection.resource)} ${selection.object.id}`).stop() } else { spinner.fail(`no ${grGreen(resource)} selected`).stop() } }