Skip to content

Commit e70649b

Browse files
committed
added a bonus flag for listing important logs
1 parent 5af8145 commit e70649b

File tree

1 file changed

+33
-28
lines changed

1 file changed

+33
-28
lines changed

src/commands/test.js

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ ${chalk.dim('Options:')}
1111
1212
-f --force Overwrite folder + file when downloading
1313
-h, --help Show usage information
14+
-l, --logs Logs to the console the value of almost every single variable
1415
-v, --version <tag> Choose the version of the rust binary that you want to be downloaded/used
1516
`
1617

@@ -21,12 +22,13 @@ module.exports = {
2122
let { print } = toolbox
2223

2324
// Read CLI parameters
24-
let { f, force, h, help, v, version } = toolbox.parameters.options
25+
let { f, force, h, help, l, logs, v, version } = toolbox.parameters.options
2526
let datasource = toolbox.parameters.first
2627

2728
// Support both long and short option variants
2829
force = force || f
2930
help = help || h
31+
logs = logs || l
3032
version = version || v
3133

3234
// Show help text if requested
@@ -35,53 +37,56 @@ module.exports = {
3537
return
3638
}
3739

38-
const platform = getPlatform();
40+
const platform = getPlatform(logs)
3941
if (!version) {
40-
let result = await fetch('https://api.github.com/repos/LimeChain/matchstick/releases/latest');
41-
let json = await result.json();
42-
version = json.tag_name;
42+
let result = await fetch('https://api.github.com/repos/LimeChain/matchstick/releases/latest')
43+
let json = await result.json()
44+
version = json.tag_name
4345
}
4446

45-
const url = `https://github.com/LimeChain/matchstick/releases/download/${version}/${platform}`;
47+
const url = `https://github.com/LimeChain/matchstick/releases/download/${version}/${platform}`
4648

47-
let binary = new Binary(platform, url, version);
48-
await binary.install(force);
49-
datasource ? binary.run(datasource) : binary.run();
49+
if (logs) {
50+
console.log(`Download link: ${url}`)
51+
}
52+
53+
let binary = new Binary(platform, url, version)
54+
await binary.install(force)
55+
datasource ? binary.run(datasource) : binary.run()
5056
}
5157
}
5258

53-
function getPlatform() {
54-
const type = os.type();
55-
const arch = os.arch();
56-
const release = os.release();
57-
const cpuCore = os.cpus()[0];
58-
const majorVersion = semver.major(release);
59-
const isM1 = cpuCore.model.includes("Apple M1");
59+
function getPlatform(logs) {
60+
const type = os.type()
61+
const arch = os.arch()
62+
const release = os.release()
63+
const cpuCore = os.cpus()[0]
64+
const majorVersion = semver.major(release)
65+
const isM1 = cpuCore.model.includes("Apple M1")
6066

61-
console.log("os type: " + type)
62-
console.log("os arch: " + arch)
63-
console.log("os release: " + release)
64-
console.log("os major version: " + majorVersion)
67+
if (logs) {
68+
console.log(`OS type: ${type}\nOS arch: ${arch}\nOS release: ${release}\nOS major version: ${majorVersion}\nCPU model: ${cpuCore.model}`)
69+
}
6570

6671
if (arch === 'x64' || (arch === 'arm64' && isM1)) {
6772
if (type === 'Darwin') {
6873
if (majorVersion === 19) {
69-
return 'binary-macos-10.15';
74+
return 'binary-macos-10.15'
7075
} else if (majorVersion === 18) {
71-
return 'binary-macos-10.14';
76+
return 'binary-macos-10.14'
7277
} else if (isM1) {
73-
return 'binary-macos-11-m1';
78+
return 'binary-macos-11-m1'
7479
}
75-
return 'binary-macos-11';
80+
return 'binary-macos-11'
7681
} else if (type === 'Linux') {
7782
if (majorVersion === 18) {
78-
return 'binary-linux-18';
83+
return 'binary-linux-18'
7984
}
80-
return 'binary-linux-20';
85+
return 'binary-linux-20'
8186
} else if (type === 'Windows_NT') {
82-
return 'binary-windows';
87+
return 'binary-windows'
8388
}
8489
}
8590

86-
throw new Error(`Unsupported platform: ${type} ${arch} ${majorVersion}`);
91+
throw new Error(`Unsupported platform: ${type} ${arch} ${majorVersion}`)
8792
}

0 commit comments

Comments
 (0)