alwaysai
Version:
The alwaysAI command-line interface (CLI)
80 lines • 3.08 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.deviceClean = void 0;
const alwayscli_1 = require("@alwaysai/alwayscli");
const cli_inputs_1 = require("../../cli-inputs");
const user_1 = require("../../components/user");
const device_1 = require("../../components/device");
const paths_1 = require("../../paths");
const util_1 = require("../../util");
const path_1 = require("path");
async function getCurrentDate() {
const dateOb = new Date();
const day = `0${dateOb.getDate()}`.slice(-2);
const month = `0${dateOb.getMonth() + 1}`.slice(-2);
const year = dateOb.getFullYear();
const hour = `0${dateOb.getHours()}`.slice(-2);
const minute = `0${dateOb.getMinutes()}`.slice(-2);
const second = `0${dateOb.getSeconds()}`.slice(-2);
return `${year}${month}${day}-${hour}${minute}${second}`;
}
exports.deviceClean = (0, alwayscli_1.CliLeaf)({
name: 'clean',
description: 'Clean the alwaysAI configurations from a device',
namedInputs: {
yes: cli_inputs_1.yesCliInput,
device: (0, alwayscli_1.CliStringInput)({
description: 'Device UUID'
}),
backup: (0, alwayscli_1.CliFlagInput)({
description: 'Keep a copy of the device configuration as a backup'
})
},
async action(_, { yes, device, backup }) {
await (0, user_1.checkUserIsLoggedInComponent)({ yes });
const deviceSelectOut = await (0, device_1.deviceSelectComponent)({
yes,
deviceId: device
});
const targetHostname = await (0, device_1.getTargetHostnameComponent)({
yes,
device: deviceSelectOut.device
});
if (targetHostname === undefined) {
throw new alwayscli_1.CliTerseError('Cannot access selected device! The device hostname is unknown.');
}
const spawner = (0, util_1.SshSpawner)({
targetHostname,
targetPath: paths_1.REMOTE_AAI_CFG_DIR_LINUX
});
if (backup === true) {
const BACKUP_REMOTE_AAI_CFG_DIR_LINUX = path_1.posix.join('~', '.config', `alwaysai.bak.${await getCurrentDate()}`);
const spinner = (0, util_1.Spinner)(`Backing up device configuration to ${BACKUP_REMOTE_AAI_CFG_DIR_LINUX}`);
try {
await spawner.run({
exe: 'cp',
args: [
'-r',
paths_1.REMOTE_AAI_CFG_DIR_LINUX,
BACKUP_REMOTE_AAI_CFG_DIR_LINUX
]
});
spinner.succeed();
}
catch (exception) {
spinner.fail();
throw exception;
}
}
const spinner = (0, util_1.Spinner)('Remove target device configuration');
try {
await spawner.sanatizedrimraf();
spinner.succeed();
}
catch (exception) {
spinner.fail();
throw exception;
}
}
});
//# sourceMappingURL=clean.js.map