Skip to content

Commit aab7fcd

Browse files
authored
fix: cli help and version commands (#110)
The help and version options were not working in the CLI interface. This happened because the arguments were not parsed correctly.
1 parent 4ce93eb commit aab7fcd

File tree

2 files changed

+13
-15
lines changed

2 files changed

+13
-15
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
"pify": "^4.0.1",
7373
"recursive-readdir": "^2.2.2",
7474
"sc-istanbul": "^0.4.5",
75-
"shelljs": "^0.8.3",
75+
"semver": "^7.3.5",
7676
"solidity-coverage": "^0.7.16",
7777
"truffle": "^5.1.65",
7878
"web3": "^1.3.4",

src/SolidityLauncher.ts

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,10 @@ export class SolidityLauncher {
152152
const additionalOptions = {}; // TODO
153153
setupOptions(this._program, additionalOptions);
154154

155-
const args = process.argv.slice(process.argv.indexOf(this._program) + 1);
155+
const index = process.argv.indexOf(process.argv.find((a) => a.includes(this._program)))
156+
157+
const args = process.argv.slice(index + 1);
158+
156159
const myConfig = loadConfig(args);
157160

158161
processConfig(myConfig, args);
@@ -187,14 +190,14 @@ export class SolidityLauncher {
187190
getUserInterface().report("asciiArt", ["Syntest"]);
188191
getUserInterface().report("version", [require("../package.json").version]);
189192

190-
if (this.config.help) {
193+
this.truffle = loadLibrary(this.config);
194+
this.api = new API(myConfig);
195+
196+
if (args.includes("--help") || args.includes("-h")) {
191197
getUserInterface().report("help", []);
192198
await this.exit();
193199
} // Exit if --help
194200

195-
this.truffle = loadLibrary(this.config);
196-
this.api = new API(myConfig);
197-
198201
setNetwork(this.config, this.api);
199202

200203
// Server launch
@@ -206,24 +209,19 @@ export class SolidityLauncher {
206209
const nodeInfo = await web3.eth.getNodeInfo();
207210
const ganacheVersion = nodeInfo.split("/")[1];
208211

209-
setNetworkFrom(this.config, accounts);
210-
211212
// Exit if --version
212-
if (this.config.version) {
213+
if (args.includes("--version") || args.includes("-v")) {
213214
getUserInterface().report("versions", [
214215
this.truffle.version,
215216
ganacheVersion,
216217
pkg.version,
217-
]); // Exit if --help
218-
219-
// Finish
220-
await tearDownTempFolders(this.tempContractsDir, this.tempArtifactsDir);
218+
]);
221219

222-
// Shut server down
223-
await this.api.finish();
224220
await this.exit();
225221
}
226222

223+
setNetworkFrom(this.config, accounts);
224+
227225
getUserInterface().report("header", ["GENERAL INFO"]);
228226

229227
getUserInterface().report("property-set", [

0 commit comments

Comments
 (0)