Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.

Commit 1ef1776

Browse files
committed
refact processHelpInput to inline check on cli.js
1 parent 0265837 commit 1ef1776

File tree

2 files changed

+21
-25
lines changed

2 files changed

+21
-25
lines changed

packages/core/cli.js

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,32 @@ const {
4646
getCommand,
4747
prepareOptions,
4848
runCommand,
49-
processHelpInput
49+
displayGeneralHelp
5050
} = require("./lib/command-utils");
5151

52-
//if `help` or `--help` is in the command, validate and transform the input
52+
//User only enter truffle with no commands, let's show them what's available.
53+
if (inputStrings.length === 0) {
54+
displayGeneralHelp();
55+
process.exit();
56+
}
57+
58+
//if `help` or `--help` is in the command, validate and transform the input argument for help
5359
if (
5460
inputStrings.some(inputString => ["help", "--help"].includes(inputString))
5561
) {
56-
//handle general help case and displayCommand Help cases and return the inputStrings to be process further
57-
processHelpInput(inputStrings);
62+
//when user wants general help
63+
if (inputStrings.length === 1) {
64+
displayGeneralHelp();
65+
process.exit();
66+
}
67+
68+
//check where is --help used, mutate argument into a proper help command
69+
const helpIndex = inputStrings.indexOf("--help");
70+
71+
if (helpIndex !== -1) {
72+
inputStrings.splice(helpIndex, 1);
73+
inputStrings.unshift("help");
74+
}
5875
}
5976

6077
const command = getCommand({

packages/core/lib/command-utils.js

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -203,26 +203,6 @@ const runCommand = async function (command, options) {
203203
return await command.run(options);
204204
};
205205

206-
const processHelpInput = inputStrings => {
207-
// handle general help case and displayCommand Help cases
208-
209-
//when user wants general help
210-
if (inputStrings.length === 0 || inputStrings.length === 1) {
211-
displayGeneralHelp();
212-
process.exit();
213-
}
214-
215-
//check where is --help used
216-
const helpIndex = inputStrings.indexOf("--help");
217-
218-
if (helpIndex !== -1) {
219-
inputStrings.splice(helpIndex, 1);
220-
inputStrings.unshift("help");
221-
}
222-
223-
return inputStrings;
224-
};
225-
226206
const displayGeneralHelp = () => {
227207
const yargs = require("yargs/yargs")();
228208
commands.forEach(command => {
@@ -327,7 +307,6 @@ const deriveConfigEnvironment = function (detectedConfig, network, url) {
327307
};
328308

329309
module.exports = {
330-
processHelpInput,
331310
displayGeneralHelp,
332311
getCommand,
333312
prepareOptions,

0 commit comments

Comments
 (0)