@gameroom/cli
Version:
A command line tool for Gameroom
27 lines (25 loc) • 967 B
JavaScript
const { printError, prompt } = require('../consoleIO'),
{ grGreen } = require('../helpers'),
{ setupEnvironment } = require('../middlewares')
module.exports = async ({ development, token, spinner }) => {
const program = require('../program')
console.log(`welcome to ${grGreen('gameroom')} ${development ? 'development' : ''}`)
// process.on('exit', () => console.log('k, bye!'))
let exit, last
while (!exit) {
let input = await prompt()
if (!input) continue
if (input === 'exit' || input === 'quit') break
if (development) input = `-d ${input}`
if (input.includes('!!')) input = input.replace('!!', last)
last = input
input = input.match(/'[^']+'|"[^"]+"|\S+/g)
for (let [index, string] of input.entries()) if (/^'.*'$/.test(string) || /^".*"$/.test(string)) input[index] = string.slice(1, -1)
input.unshift(null, null)
try {
await program.parse(input)
} catch(err) {
printError(err)
}
}
}