diff --git a/packages/ethernaut-ui/src/index.js b/packages/ethernaut-ui/src/index.js index b0ff5ea9..c47014c1 100644 --- a/packages/ethernaut-ui/src/index.js +++ b/packages/ethernaut-ui/src/index.js @@ -3,7 +3,6 @@ const requireAll = require('common/src/require-all') const makeTasksInteractive = require('./internal/make-interactive') const spinner = require('common/src/spinner') -requireAll(__dirname, 'scopes') requireAll(__dirname, 'tasks') extendEnvironment((hre) => { diff --git a/packages/ethernaut-ui/src/internal/collect-args.js b/packages/ethernaut-ui/src/internal/collect-args.js index b1541ae7..c7674dc5 100644 --- a/packages/ethernaut-ui/src/internal/collect-args.js +++ b/packages/ethernaut-ui/src/internal/collect-args.js @@ -16,7 +16,10 @@ module.exports = async function collectArguments(providedArgs, task, hre) { const collectedArgs = {} for (let paramDef of paramDefinitions) { - if (paramDef.name === 'nonInteractive') continue + if (paramDef.name === 'nonInteractive') { + collectedArgs['nonInteractive'] = false + continue + } const providedArg = providedArgs[paramDef.name] const parsedArg = paramDef.parsedValue @@ -57,7 +60,7 @@ async function collectArg(paramDef, providedArg, parsedArg, argsSoFar) { providedArg === paramDef.defaultValue && parsedArg === undefined if (!isInjectedDefault) { debug.log('Value was provided by the user, skipping autocompletion', 'ui') - return providedArg + return undefined } } diff --git a/packages/ethernaut-ui/src/internal/make-interactive.js b/packages/ethernaut-ui/src/internal/make-interactive.js index fd67ce47..771951af 100644 --- a/packages/ethernaut-ui/src/internal/make-interactive.js +++ b/packages/ethernaut-ui/src/internal/make-interactive.js @@ -96,7 +96,7 @@ function makeInteractive(task) { args = { ...args, ...collectedArgs } // If parameters were collected, print out the call - if (Object.values(collectedArgs).length > 0) { + if (Object.values(collectedArgs).length > 1) { output.info(toCliSyntax(args, task)) } } @@ -116,27 +116,26 @@ function makeInteractive(task) { function toCliSyntax(args, task) { const name = task.scope ? `${task.scope} ${task.name}` : task.name - const printArgs = Object.entries(args) - .map(([argName, value]) => { - const isPositional = task.positionalParamDefinitions.some( - (p) => p.name === argName, - ) - - if (isPositional) { - return value + const printArgs = [] + Object.entries(args).forEach(([argName, value]) => { + const isPositional = task.positionalParamDefinitions.some( + (p) => p.name === argName, + ) + + if (isPositional) { + printArgs.push(value) + } else { + const isFlag = task.paramDefinitions[argName]?.isFlag + argName = camelToKebabCase(argName) + if (isFlag) { + if (value === true) printArgs.push(`--${argName}`) } else { - const isFlag = task.paramDefinitions[argName]?.isFlag - argName = camelToKebabCase(argName) - if (isFlag) { - if (value === true) return `--${argName}` - else return '' - } else { - if (value !== undefined) return `--${argName} '${value}'` - else return '' - } + if (value !== undefined) printArgs.push(`--${argName} '${value}'`) } - }) - .join(' ') + } + }) + + const printStr = printArgs.join(' ') - return `ethernaut ${name} ${printArgs}` + return `ethernaut ${name} ${printStr}` }