vodafone-station-cli
Version:
Access your Vodafone Station from the comfort of the command line.
48 lines (47 loc) • 1.8 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const core_1 = require("@oclif/core");
const base_command_1 = tslib_1.__importStar(require("../base-command"));
const discovery_1 = require("../modem/discovery");
const factory_1 = require("../modem/factory");
class Restart extends base_command_1.default {
static description = 'restart the modem/router';
static examples = [
'$ vodafone-station-cli restart',
'$ vodafone-station-cli restart --ip 192.168.100.1',
];
static flags = {
ip: (0, base_command_1.ipFlag)(),
password: core_1.Flags.string({
char: 'p',
description: 'router/modem password',
}),
};
async run() {
const { flags } = await this.parse(Restart);
const password = flags.password ?? process.env.VODAFONE_ROUTER_PASSWORD;
if (!password || password === '') {
this.log('You must provide a password either using -p or by setting the environment variable VODAFONE_ROUTER_PASSWORD');
return;
}
const discoveryOptions = {
ip: flags.ip,
};
const modemLocation = await (0, discovery_1.discoverModemLocation)(discoveryOptions);
const discoveredModem = await new discovery_1.ModemDiscovery(modemLocation, this.logger).discover();
const modem = (0, factory_1.modemFactory)(discoveredModem, this.logger);
try {
await modem.login(password);
await modem.restart();
this.log('The modem has been restarted.');
}
catch (error) {
this.log('Something went wrong.', error);
}
finally {
await modem.logout();
}
}
}
exports.default = Restart;