Skip to content

Commit

Permalink
Fix autocompleted message
Browse files Browse the repository at this point in the history
  • Loading branch information
eternauta1337 committed Mar 3, 2024
1 parent 54129ad commit 23fc22c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 24 deletions.
1 change: 0 additions & 1 deletion packages/ethernaut-ui/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
7 changes: 5 additions & 2 deletions packages/ethernaut-ui/src/internal/collect-args.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
}

Expand Down
41 changes: 20 additions & 21 deletions packages/ethernaut-ui/src/internal/make-interactive.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
Expand All @@ -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}`
}

0 comments on commit 23fc22c

Please sign in to comment.