@gameroom/cli
Version:
A command line tool for Gameroom
369 lines (365 loc) • 14 kB
JavaScript
const { command, option } = require('termkit'),
{ priceCharting, report, shopify, shopifyV2, create, dateString, deleteAction, deselect, find, gameroom, get, googleFeed, inspect, login, logout, print, prototype, qr, resurrect, scp, select, selections, ssh, test, timeclock, update, updateUnits, vnc } = require('../actions'),
{ checkDir, getConsoleProducts, getContainers, getId, getModel, getShopifyStores, getTimeframe, handleExit, lock, resolvePath, setupConfig, setupEnvironment, setupHeaders, setupShopify } = require('../middlewares'),
{ version } = require('../../package.json'),
{ console_options, timeframe_options } = require('./options')
require('./exitHandler')
const program = command('gameroom')
.version(version)
.description('a cli for the gameroom ecosystem')
.options([
option('t', 'token', '<token>', 'supply auth token'),
option('d', 'development', null, 'run in development environment')
// option('s', 'selections', '<selections>', 'Supply selections object')
])
.middleware(checkDir)
// .middleware(lock)
.middleware(setupEnvironment)
.middleware(setupHeaders)
.middleware(setupConfig)
.middleware(setupShopify)
// .middleware(handleExit)
// .action(gameroom)
.commands([
//price-charting-update
command('price-charting')
.description('compare gameroom products to price charting api')
.commands([
command('ratio-in', '<path>')
.description ('import game plus ratio csv')
.middleware(resolvePath)
.action(priceCharting.ratioIn),
command('ratio-out', '<path>')
.description ('export game plus ratio csv')
.options([
...console_options
])
.middleware(resolvePath)
.middleware(getConsoleProducts)
.action(priceCharting.ratioOut),
command('prices-out', '<path>')
.description ('export game prices csv')
.options([
...console_options
])
.middleware(resolvePath)
.middleware(getConsoleProducts)
.action(priceCharting.pricesOut),
command('reprice')
.description('reprice console products')
.options([
option('w', 'write', '<path>', 'write csv file with repricing data'),
...console_options
])
.middleware(getConsoleProducts)
.action(priceCharting.reprice),
command('update')
.description('update products from price charting')
.options([
option('w', 'write', '<path>', 'write csv file with repricing data'),
...console_options
])
.middleware(getConsoleProducts)
.action(priceCharting.update),
]),
// report
command('report')
.description('generate reports')
.commands([
// report auto-priced
command('auto-priced')
.description ('generate an auto priced products report')
.options([
option('w', 'write', '[dir]', 'write to csv file'),
...console_options
])
.middleware(getConsoleProducts)
.action(report.autoPriced),
// report container-units
command('container-units')
.description('generate a container units report')
.options([
option('w', 'write', '[dir]', 'write to csv file')
])
.action(report.containerUnits),
// created units
command('created-units')
.description('generate a created units report')
.options([
// date filters
...timeframe_options,
// filters
option('i', 'id', '<id>', 'filter by user id'),
// csv
option('w', 'write', '[dir]', 'write to csv file')
])
.middleware(getTimeframe)
.action(report.createdUnits),
// report changelogs
command('changelogs')
.description('generate a changelogs report')
.options([
// date filters
...timeframe_options,
// filters
option('i', 'id', '<id>', 'filter by user id'),
option(null, 'email', '<email>', 'filter by user email'),
option('f', 'first', '<name>', 'filter by user first name'),
option('l', 'last', '<name>', 'filter by user last name'),
// csv
option('v', 'verbose', null, 'additional output'),
option('w', 'write', '[dir]', 'write to csv file')
])
.middleware(getTimeframe)
.action(report.changelogs),
// report deletes
command('deletes')
.description('generate a deletes report')
.option('v', 'verbose', null, 'additional output')
// user filters
.option('i', 'id', '<id>', 'filter by user id')
.option('e', 'email', '<email>', 'filter by user email')
.option('f', 'first', '<name>', 'filter by user first name')
.option('l', 'last', '<name>', 'filter by user last name')
// csv
.option('w', 'write', '[dir]', 'write to csv file')
.action(report.deletes),
// report lines
command('lines')
.description('generate a lines report')
.options([
...timeframe_options,
option('w', 'write', '[dir]', 'write report to file')
])
.middleware(getTimeframe)
.action(report.lines),
// report payments
command('payments')
.description('generate a payments report')
.options([
...timeframe_options,
])
.middleware(getTimeframe)
.action(report.payments),
// report repairs
command('repairs')
.description('generate a repairs report')
.options([
...timeframe_options,
option('w', 'write', '[dir]', 'write report to file')
])
.middleware(getTimeframe)
.action(report.repairs),
// report sales
command('sales')
.description('generate a sales report')
.options([
...timeframe_options,
])
.middleware(getTimeframe)
.action(report.sales),
// report small-cash-payouts
command('small-cash-payouts')
.description('generate a small cash payouts report')
.middleware(getTimeframe)
.options([
...timeframe_options,
option('t', 'target', '[amount]', 'target max amout for report')
])
.action(report.smallCashPayouts),
// report timecards
command('timecards')
.description('generate a timecards report')
.options([
...timeframe_options,
// filters
option('i', 'id', '<id>', 'filter by user id'),
option(null, 'email', '<email>', 'filter by user email'),
option('f', 'first', '<name>', 'filter by user first name'),
option('l', 'last', '<name>', 'filter by user last name'),
// csv
option('w', 'write', '[dir]', 'write to csv file')
])
.middleware(getTimeframe)
.action(report.timecards)
]),
// shopify
command('shopify')
.description('shopify commands')
.commands([
// shopify audit
command('audit')
.description('audit shopify products')
.option('o', 'out', null, 'remove shopify products with zero quantity')
.option('v', 'verbose', null, 'print more output')
.action(shopify.audit),
// shopify update
command('update')
.description('update shopify inventory')
.option('v', 'verbose', null, 'print more output')
.action(shopify.update),
]),
// shopifyV2
command('shopifyV2')
.description('shopify commands')
.commands([
// shopify config
command('config')
.description('update shopify config')
.commands([
// shopify config print
command('print')
.description('audit shopify products')
.action(shopifyV2.config.print),
// shopify config reset
command('reset')
.description('reset shopify config')
.action(shopifyV2.config.reset),
// shopify config update
command('update')
.description('update shopify config')
.option('o', 'order', '<order>', 'update last shopify order number')
.option('d', 'date', '[date]', 'update last shopify push date')
.action(shopifyV2.config.update)
]),
// shopify audit
command('audit')
.description('audit shopify products')
.option('v', 'verbose', null, 'print more output')
.action(shopifyV2.audit),
// shopify pull
command('pull')
.description('pull orders from shopify')
.option('v', 'verbose', null, 'print more output')
.action(shopifyV2.pull),
// shopify push
command('push')
.description('push inventory to shopify')
.option('v', 'verbose', null, 'print more output')
.middleware(getShopifyStores)
.middleware(getContainers)
.action(shopifyV2.push)
]),
// create
command('create', '[resource] [attributes]')
.description('create an object with a supplied resource and attributes')
.middleware(getModel)
.action(create),
command('date-string', '<seconds>')
.description('get a date string from seconds since Jan 1,1970')
.action(dateString),
// delete
command('delete', '[resource] [id]')
.description('delete an object with a supplied resource and id')
.middleware(getModel)
.middleware(getId)
.action(deleteAction),
// deselect
command('deselect', '[resource]')
.description('deselect a resource (<all> to remove all selections)')
.action(deselect),
// find
command('find', '[resource] [id]')
.description('find a object with a supplied resource and id')
.option('i', 'include', '[keys...]', 'include keys in output')
.option('e', 'exclude', '[keys...]', 'exclude keys from output')
.middleware(getModel)
.middleware(getId)
.action(find),
// get
command('get', '[resource] [query]')
.description('get a list of objects for a supplied resource')
.option('f', 'filter', '<object>', 'set filter object')
.option('s', 'sort', '<object>', 'set sort object')
.option('l', 'limit', '<number>', 'set limit for fetch, default 100')
.option('o', 'offset', '<number>', 'set offset for fetch')
.option('i', 'include', '[keys...]', 'include keys in output')
.option('e', 'exclude', '[keys...]', 'exclude keys from output')
// .option('v', 'view', '<string>', 'set view for fetch')
// option('t', 'table', null, 'Display result as a table')
.middleware(getModel)
.action(get),
// google-feed
command('google-feed')
.description('update a merchant feed to google')
.action(googleFeed),
// inspect
command('inspect', '[resource] [id]')
.middleware(getModel)
.middleware(getId)
.description('find a object with a supplied resource and id')
.action(inspect),
// login
command('login')
.description('log in to Gameroom')
.option('e', 'email', '<email>', 'set filter object')
.option('p', 'password', '<password>', 'set sort object')
.action(login),
// logout
command('logout')
.description('log out of gameroom')
.action(logout),
// prototype
command('prototype', '[resource]')
.description('print a prototype object of given resource type')
.middleware(getModel)
.action(prototype),
// qr
command('qr', '<data>')
.description('print a qr code with given data')
.action(qr),
// resurrect
command('resurrect', '[id]')
.description('resurrect a deleted item')
.middleware(getId)
.action(resurrect),
// scp
command('scp', '[source] [location] [device] [destination]')
.description('transfer file with scp, default destination is ~/downloads')
.option('l', 'local', null, 'attempt local connection')
.action(scp),
// select
command('select', '[resource] [id]')
.description('select a resource with given id')
.middleware(getModel)
.middleware(getId)
.action(select),
// selections
command('selections')
.description('view selections')
.option('v', 'verbose', null, 'get verbose response')
.action(selections),
// ssh
command('ssh', '[location] [device] [command]')
.description('connect with ssh')
.option('l', 'local', null, 'attempt local connection')
.option('n', 'new-window', null, 'connect in new window')
.action(ssh),
// test
command('test')
.description('test something on gameroom')
.action(test),
// timeclock
command('timeclock')
.description('list clocked in users')
.action(timeclock),
// update
command('update', '[resource] [id] [attributes]')
.description('update an object with a supplied resource, id, and attributes')
.middleware(getModel)
.middleware(getId)
.action(update),
command('update-units')
.description('update units from their products')
.action(updateUnits),
// version
command('version')
.description('print current version')
.action(() => console.log(`v${version}`)),
// vnc
command('vnc', '[location] [device]')
.description('connect with vnc')
.option('l', 'local', null, 'attempt local connection')
.action(vnc),
])
module.exports = program