alwaysai
Version:
The alwaysAI command-line interface (CLI)
66 lines • 2.7 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.targetHostnameCheckComponent = void 0;
const alwayscli_1 = require("@alwaysai/alwayscli");
const util_1 = require("../../util");
const general_1 = require("../general");
const set_up_passwordless_ssh_component_1 = require("../general/set-up-passwordless-ssh-component");
async function targetHostnameCheckComponent(props) {
var _a;
let targetHostname = (_a = props.targetHostname) !== null && _a !== void 0 ? _a : '';
let connected = false;
while (!connected) {
if (props.prompt) {
targetHostname = await promptForTargetHostname();
}
try {
if (props.prompt) {
await (0, general_1.connectBySshComponent)({
targetHostname,
warnOrFail: 'warn'
});
}
else {
await (0, util_1.connectBySsh)({ targetHostname });
}
connected = true;
}
catch (exception) {
if (exception &&
exception.code === alwayscli_1.CLI_TERSE_ERROR &&
typeof exception.message === 'string' &&
(exception.message.includes(util_1.PROCESS_EXITED_WITH_NON_ZERO_STATUS_CODE) ||
exception.message.includes(util_1.TIMED_OUT_CONNECTING_TO))) {
if (exception.message.includes('Permission denied')) {
await (0, set_up_passwordless_ssh_component_1.setUpPasswordlessSshComponent)({ targetHostname });
connected = true;
}
else {
(0, util_1.echo)(exception.message);
(0, util_1.echo)('Cannot connect to your device. Please check the address and try again.');
}
}
else {
throw exception;
}
}
}
return targetHostname;
async function promptForTargetHostname() {
const answers = await (0, util_1.promptForInput)({
purpose: 'for the target hostname',
questions: [
{
type: 'text',
name: 'hostname',
message: 'Please enter the hostname (with optional user name) to connect to your device via ssh (e.g. "pi@1.2.3.4"):',
initial: targetHostname,
validate: (value) => (!value ? 'Value is required' : true)
}
]
});
return answers.hostname;
}
}
exports.targetHostnameCheckComponent = targetHostnameCheckComponent;
//# sourceMappingURL=target-hostname-check-component.js.map