-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathrestart.ts
51 lines (45 loc) · 1.46 KB
/
restart.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import {Flags} from '@oclif/core'
import Command from '../base-command'
import {discoverModemIp, ModemDiscovery} from '../modem/discovery'
import {modemFactory} from '../modem/factory'
export default class Restart extends Command {
static description =
'Restart the router/modem';
static examples = [
'$ vodafone-station-cli restart -p PASSWORD',
];
static flags = {
password: Flags.string({
char: 'p',
description: 'router/modem password',
}),
};
async restartRouter(password: string): Promise<unknown> {
const modemIp = await discoverModemIp()
const discoveredModem = await new ModemDiscovery(modemIp, this.logger).discover()
const modem = modemFactory(discoveredModem, this.logger)
try {
await modem.login(password)
const restart = await modem.restart()
return restart
} catch (error) {
this.log('Something went wrong.', error)
this.error(error as Error)
} finally {
await modem.logout()
}
}
async run(): Promise<void> {
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'
)
this.exit()
}
this.log('Restarting router... this could take some time...')
await this.restartRouter(password!)
this.exit()
}
}