forked from lukealford/abb-speedtest-cli
-
Notifications
You must be signed in to change notification settings - Fork 1
/
cli.js
executable file
·70 lines (62 loc) · 2.03 KB
/
cli.js
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
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env node
/**
* Module dependencies.
*/
var program = require('commander');
var runSpeedTest = require('./index').runSpeedTest;
const homedir = require('os').homedir();
const path = require('path');
const fs = require('fs');
program
.version('1.3.5')
.description('Runs a speedtest using speed.aussiebroadband.com.au')
.option('-l, --location [Sydney] [optional]', 'use specific server location')
.option('-q, --quiet [optional]', 'silences the progress console output messages (errors still outputed)')
.option('-h, --hide [optional]', 'disables result reporting to ABB')
.option('-j, --json [optional]', 'return json')
.option('-c, --csv [optional]', 'return csv format')
.option('-d, --dcsv [optional]', 'return csv format in speedtest-cli shape (non-save flow only)')
.option('-s, --save [optional]', 'saves format to user\\Documents\\abb-speedtests, requires you to set a format')
.option('-o, --output [optional]', 'overwrites output location')
.action(function(req,optional){
let dir = '';
if(program.save){
dir = homedir+path.sep+"Documents"+path.sep+"abb-speedtests";
try {
checkFolder(dir)
console.log('Saving result default directory:', dir)
} catch (err) {
console.error(err)
}
}
if(program.save == true && program.output){
console.log(program.output)
dir = program.output;
try {
checkFolder(dir)
console.log('Saving result to input directory:', dir)
} catch (err) {
console.error(err)
}
}
let option = {
location: program.location,
quiet: program.quiet,
hide: program.hide,
json:program.json,
csv:program.csv,
dcsv:program.dcsv,
save:program.save,
output:program.output,
saveDir: dir
}
runSpeedTest(option);
})
program.parse(process.argv);
function checkFolder (dirpath) {
try {
fs.mkdirSync(dirpath, { recursive: true })
} catch (err) {
if (err.code !== 'EEXIST') throw err
}
}