alwaysai
Version:
The alwaysAI command-line interface (CLI)
55 lines • 2.04 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.deviceSelectComponent = void 0;
const alwayscli_1 = require("@alwaysai/alwayscli");
const chalk = require("chalk");
const util_1 = require("../../util");
const device_add_component_1 = require("./device-add-component");
const infrastructure_1 = require("../../infrastructure");
async function deviceSelectComponent(props) {
const { yes, deviceId } = props;
if (deviceId) {
const device = await (0, infrastructure_1.getDeviceByUuid)({ uuid: deviceId });
return { device, new: false };
}
if (yes && !deviceId) {
throw new alwayscli_1.CliUsageError((0, util_1.RequiredWithYesMessage)('deviceId'));
}
const { username } = await (0, infrastructure_1.CliAuthenticationClient)().getInfo();
const userDevices = await (0, infrastructure_1.CliRpcClient)().getUserDevices({
user_name: username
});
const choices = [
{ title: chalk.green.bold('Add a new device'), value: 'new' }
];
userDevices.forEach((device, index) => {
choices.push({
title: `${device.friendly_name} (${device.mode})`,
value: `${index}`
});
});
const choice = await (0, util_1.promptForInput)({
purpose: 'to select a target device',
questions: [
{
type: 'select',
name: 'targetDevice',
message: 'select a target device',
initial: 0,
choices
}
]
});
let selectedDevice;
if (choice.targetDevice === 'new') {
const device = await (0, device_add_component_1.deviceAddComponent)({ yes });
selectedDevice = device;
}
else {
const device = userDevices[choice.targetDevice];
selectedDevice = device;
}
return { device: selectedDevice, new: choice.targetDevice === 'new' };
}
exports.deviceSelectComponent = deviceSelectComponent;
//# sourceMappingURL=device-select-component.js.map