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

Commit

Permalink
core(cli): factor displayGeneralHelp to use isREPL context
Browse files Browse the repository at this point in the history
  • Loading branch information
cds-amal committed Feb 12, 2023
1 parent 17cbe98 commit b3f4507
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/core/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const inputArguments = process.argv.slice(2);
// handle cases where input indicates the user wants to access Truffle's help
const { displayHelp, inputStrings } = handleHelpInput({ inputArguments });
if (displayHelp) {
displayGeneralHelp({});
displayGeneralHelp();
process.exit();
}

Expand Down
15 changes: 13 additions & 2 deletions packages/core/lib/command-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ const { extractFlags } = require("./utils/utils"); // contains utility methods
const globalCommandOptions = require("./global-command-options");
const debugModule = require("debug");
const debug = debugModule("core:command:run");
const { validTruffleCommands } = require("./commands/commands");
const {
validTruffleCommands,
validTruffleConsoleCommands
} = require("./commands/commands");
const Web3 = require("web3");
const TruffleError = require("@truffle/error");

Expand Down Expand Up @@ -294,8 +297,16 @@ const runCommand = async function (command, options) {
return await command.run(options);
};

const displayGeneralHelp = ({ commands = validTruffleCommands }) => {
/**
* Display general help for Truffle commands
* @param {Object} options - options object
* @param {Boolean} options.isREPL - whether or not the help is being displayed in a REPL
* @returns {void}
*/
const displayGeneralHelp = options => {
const yargs = require("yargs/yargs")();
const isREPL = options?.isREPL ?? false; //default to not displaying REPL commands
const commands = isREPL ? validTruffleConsoleCommands : validTruffleCommands;
commands.forEach(command => {
// Exclude "install" and "publish" commands from the generated help list
// because they have been deprecated/removed.
Expand Down
3 changes: 1 addition & 2 deletions packages/core/lib/console-child.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const {
displayGeneralHelp
} = require("./command-utils");
const { handleHelpInput } = require("./cliHelp");
const { validTruffleConsoleCommands } = require("./commands/commands");

// we split off the part Truffle cares about and need to convert to an array
const input = process.argv[2].split(" -- ");
Expand All @@ -19,7 +18,7 @@ const inputArguments = parseQuotesAndEscapes(input[1], escapeCharacters); //note
// handle cases where input indicates the user wants to access Truffle's help
const { displayHelp, inputStrings } = handleHelpInput({ inputArguments });
if (displayHelp) {
displayGeneralHelp({ commands: validTruffleConsoleCommands });
displayGeneralHelp({ isREPL: true });
process.exit();
}

Expand Down

0 comments on commit b3f4507

Please sign in to comment.