Add support for passing custom parameters to script
This commit is contained in:
@@ -7,22 +7,26 @@ import io.smnp.cli.model.enumeration.ModulesPrintMode
|
||||
import io.smnp.environment.DefaultEnvironment
|
||||
import io.smnp.ext.DefaultModuleRegistry
|
||||
import io.smnp.interpreter.DefaultInterpreter
|
||||
import io.smnp.type.model.Value
|
||||
|
||||
fun main(args: Array<String>): Unit = mainBody {
|
||||
ArgParser(args).parseInto(::Arguments).run {
|
||||
val interpreter = DefaultInterpreter()
|
||||
val environment = DefaultEnvironment()
|
||||
|
||||
environment.setVariable("__param__", Value.wrap(parameters.toMap()))
|
||||
|
||||
when {
|
||||
file != null -> interpreter.run(file!!, printTokens, printAst, dryRun)
|
||||
code != null -> interpreter.run(code!!, printTokens, printAst, dryRun)
|
||||
file != null -> interpreter.run(file!!, environment, printTokens, printAst, dryRun)
|
||||
code != null -> interpreter.run(code!!, environment, printTokens, printAst, dryRun)
|
||||
else -> null
|
||||
}?.let { it as DefaultEnvironment }?.let { environment ->
|
||||
}?.let { it as DefaultEnvironment }?.let { disposedEnvironment ->
|
||||
if(loadedModules != null) {
|
||||
println("Loaded modules:")
|
||||
when (loadedModules) {
|
||||
ModulesPrintMode.LIST -> environment.modules.forEach { println(it) }
|
||||
ModulesPrintMode.TREE -> environment.printModules(false)
|
||||
ModulesPrintMode.CONTENT -> environment.printModules(true)
|
||||
ModulesPrintMode.LIST -> disposedEnvironment.modules.forEach { println(it) }
|
||||
ModulesPrintMode.TREE -> disposedEnvironment.printModules(false)
|
||||
ModulesPrintMode.CONTENT -> disposedEnvironment.printModules(true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user