Skip to content

Commit eecc637

Browse files
authored
Merge pull request #778 from georg-getz/master
Added a new flag for logging additional information when running graph test and fixed an issue in the if statements
2 parents 67440ee + db7ac9e commit eecc637

File tree

1 file changed

+37
-27
lines changed

1 file changed

+37
-27
lines changed

src/commands/test.js

Lines changed: 37 additions & 27 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 information about the OS, CPU model and download url (debugging purposes)
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,48 +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")
66+
67+
if (logs) {
68+
console.log(`OS type: ${type}\nOS arch: ${arch}\nOS release: ${release}\nOS major version: ${majorVersion}\nCPU model: ${cpuCore.model}`)
69+
}
6070

6171
if (arch === 'x64' || (arch === 'arm64' && isM1)) {
6272
if (type === 'Darwin') {
63-
if (majorVersion === '19') {
64-
return 'binary-macos-10.15';
65-
} else if (majorVersion === '18') {
66-
return 'binary-macos-10.14';
73+
if (majorVersion === 19) {
74+
return 'binary-macos-10.15'
75+
} else if (majorVersion === 18) {
76+
return 'binary-macos-10.14'
6777
} else if (isM1) {
68-
return 'binary-macos-11-m1';
78+
return 'binary-macos-11-m1'
6979
}
70-
return 'binary-macos-11';
80+
return 'binary-macos-11'
7181
} else if (type === 'Linux') {
72-
if (majorVersion === '18') {
73-
return 'binary-linux-18';
82+
if (majorVersion === 18) {
83+
return 'binary-linux-18'
7484
}
75-
return 'binary-linux-20';
85+
return 'binary-linux-20'
7686
} else if (type === 'Windows_NT') {
77-
return 'binary-windows';
87+
return 'binary-windows'
7888
}
7989
}
8090

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

0 commit comments

Comments
 (0)