Create base for CLI
This commit is contained in:
@@ -1,9 +1,35 @@
|
||||
package io.smnp
|
||||
|
||||
import com.xenomachina.argparser.ArgParser
|
||||
import com.xenomachina.argparser.mainBody
|
||||
import io.smnp.cli.model.entity.Arguments
|
||||
import io.smnp.cli.model.enumeration.ModulesPrintMode
|
||||
import io.smnp.environment.DefaultEnvironment
|
||||
import io.smnp.ext.DefaultModuleRegistry
|
||||
import io.smnp.interpreter.DefaultInterpreter
|
||||
import java.io.File;
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val interpreter = DefaultInterpreter()
|
||||
interpreter.run(File("/home/bartek/Developent/SMNP-Kotlin/examples/scratchpad.mus"))
|
||||
fun main(args: Array<String>): Unit = mainBody {
|
||||
ArgParser(args).parseInto(::Arguments).run {
|
||||
val interpreter = DefaultInterpreter()
|
||||
|
||||
when {
|
||||
file != null -> interpreter.run(file!!, printTokens, printAst, dryRun)
|
||||
code != null -> interpreter.run(code!!, printTokens, printAst, dryRun)
|
||||
else -> null
|
||||
}?.let { it as DefaultEnvironment }?.let { environment ->
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (availableModules) {
|
||||
println("Available modules:")
|
||||
DefaultModuleRegistry.registeredModules().forEach { println(it) }
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user