UNPKG

@gameroom/cli

Version:

A command line tool for Gameroom

36 lines (31 loc) 1.32 kB
const prompt = require('./prompt'), { grGreen } = require('../helpers'), { default_ports, devices } = require('../refs') module.exports = async (service, options) => { let { local, location, device } = options // Location if (!location) location = await prompt('location: ') // Shortcuts if (location === 'dt') location = 'downtown' location = devices[location] if (!location) throw new Error(`location ${grGreen(options.location)} not configured`) let url if (!local) { url = location.url || location.ip if (!url) throw new Error(`location ${grGreen(options.location)} has no url or ip`) } // Device if (!device) device = await prompt('device: ') device = location.devices[device] if (!device) throw new Error(`device ${grGreen(options.device)} for location ${grGreen(options.location)} not configured`) let port = default_ports[service] if (local) { if (!device.name && !device.ip) throw new Error(`device ${grGreen(options.device)} has no name or ip`) url = `${device.name || device.ip}.local` } else { if (!device.ports) throw new Error(`device ${grGreen(options.device)} has no ports configured`) port = device.ports[service] } if (!port) throw new Error(`device ${grGreen(options.device)} is not configured for ${service}`) return { url, port } }