MCPcopy Create free account
hub / github.com/breck7/scroll / runCommand

Method runCommand

external/.scrollLibs.js:13998–14011  ·  view source on GitHub ↗
(instance, command = "", param = undefined)

Source from the content-addressed store, hash-verified

13996 return folder.replace(/\/$/, "") + "/"
13997 }
13998 static runCommand(instance, command = "", param = undefined) {
13999 const run = name => {
14000 console.log(`Running ${name}:`)
14001 instance[name](param)
14002 }
14003 if (instance[command + "Command"]) return run(command + "Command")
14004 // Get commands from both the child and parent classes
14005 const classes = [Object.getPrototypeOf(instance), Object.getPrototypeOf(Object.getPrototypeOf(instance))]
14006 const allCommands = classes.map(classInstance => Object.getOwnPropertyNames(classInstance).filter(atom => atom.endsWith("Command"))).flat()
14007 allCommands.sort()
14008 const commandAsNumber = parseInt(command) - 1
14009 if (command.match(/^\d+$/) && allCommands[commandAsNumber]) return run(allCommands[commandAsNumber])
14010 console.log(`\n❌ No command provided. Available commands:\n\n` + allCommands.map((name, index) => `${index + 1}. ${name.replace("Command", "")}`).join("\n") + "\n")
14011 }
14012 static removeReturnChars(str = "") {
14013 return str.replace(/\r/g, "")
14014 }

Callers

nothing calls this directly

Calls 7

mapMethod · 0.80
sortMethod · 0.80
logMethod · 0.80
replaceMethod · 0.80
runFunction · 0.70
filterMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected