UNPKG

snips-sam

Version:

The Snips Assistant Manager

56 lines (46 loc) 2.01 kB
import chalk from 'chalk'; import * as yargs from 'yargs'; import { cli } from '../cli'; import { Device, DeviceStatus } from '../models/device'; import { SSHService } from '../session/ssh'; exports.command = 'status'; exports.desc = 'Show the status of your device'; exports.handler = async (argv: yargs.Argv) => { cli.stream.loading('Fetching device status...'); const ssh = new SSHService(); await ssh.connect().catch(e => cli.stream.error(e)); const device = new Device(); device.name = ssh.credentials.hostname; device.osVersion = await ssh.getOSVersion(); const isAssistantInstalled = await ssh.isAssistantInstalled(); device.status = isAssistantInstalled ? DeviceStatus.LIVE : DeviceStatus.LIVE_NO_ASSISTANT; cli.stream.stopAndClear(); let statusString; switch (device.status) { case DeviceStatus.LIVE: statusString = chalk`{green Live}`; break; case DeviceStatus.LIVE_NO_ASSISTANT: statusString = chalk`{green Live} (no assistant)`; break; default: statusString = 'Not live'; break; } let statusText = chalk`Connected to device {blue ${device.name}}\n`; statusText += `OS version ........... ${device.osVersion}\n`; statusText += `Status ............... ${statusString}\n`; const packagesVersion: string | void = await ssh.packagesVersion() .catch((e) => { cli.stream.error('Error connecting to your device: ' + e.message); process.exit(); }); cli.stream.print(statusText); if (packagesVersion === undefined) { cli.stream.print('No Snips packages detected'); } else { cli.stream.print(packagesVersion + '\n'); } const servicesStatus = await ssh.snipsServicesSystemctlStatus() .catch((e) => {}); if (servicesStatus !== undefined) { servicesStatus.forEach((service) => { cli.stream.print(`${service.name} ${service.active ? chalk.green('running') : chalk.red('failing')}`); }); } ssh.disconnect(); };