-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathdiagnose.ts
58 lines (48 loc) · 1.67 KB
/
diagnose.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
52
53
54
55
56
57
import { Flags } from '@oclif/core';
import Command from '../base-command';
import DocsisDiagnose from "../modem/docsis-diagnose";
import { TablePrinter } from "../modem/printer";
import { webDiagnoseLink } from "../modem/web-diagnose";
import { getDocsisStatus } from "./docsis";
export default class Diagnose extends Command {
static description =
'Diagnose the quality of the docsis connection.';
static examples = [
'$ vodafone-station-cli diagnose',
];
static flags = {
password: Flags.string({
char: 'p',
description: 'router/modem password',
}),
web: Flags.boolean({
char: 'w',
description: 'review the docsis values in a webapp',
}),
};
async run(): Promise<void> {
const { flags } = await this.parse(Diagnose)
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()
}
try {
const docsisStatus = await getDocsisStatus(password!, this.logger)
const diagnoser = new DocsisDiagnose(docsisStatus)
const tablePrinter = new TablePrinter(docsisStatus);
this.log(tablePrinter.print())
if (diagnoser.hasDeviations()) {
this.logger.warn("Docsis connection connection quality deviation found!")
}
if (flags.web) {
this.log(`Review your docsis state online -> ${webDiagnoseLink(docsisStatus)}`)
}
this.log(diagnoser.printDeviationsConsole())
} catch (error) {
this.error(error as Error, { message: "Something went wrong" })
}
}
}