mirror of
https://github.com/slhaf/Partner.git
synced 2026-05-12 08:43:02 +08:00
feat(partnerctl): add main command with init/run/module and chat demo subcommands
This commit is contained in:
@@ -0,0 +1,33 @@
|
|||||||
|
package work.slhaf.partner.ctl
|
||||||
|
|
||||||
|
import picocli.AutoComplete
|
||||||
|
import picocli.CommandLine
|
||||||
|
import work.slhaf.partner.ctl.commands.*
|
||||||
|
import kotlin.system.exitProcess
|
||||||
|
|
||||||
|
@CommandLine.Command(
|
||||||
|
name = "partnerctl",
|
||||||
|
mixinStandardHelpOptions = true,
|
||||||
|
version = ["partnerctl 0.1.0"],
|
||||||
|
subcommands = [
|
||||||
|
InitCommand::class,
|
||||||
|
RunCommand::class,
|
||||||
|
ChatCommand::class,
|
||||||
|
ConfigCommand::class,
|
||||||
|
ModuleCommand::class,
|
||||||
|
AutoComplete.GenerateCompletion::class
|
||||||
|
],
|
||||||
|
description = ["Partner command line tool."]
|
||||||
|
)
|
||||||
|
class PartnerCtl : Runnable {
|
||||||
|
|
||||||
|
override fun run() {
|
||||||
|
CommandLine.usage(this, System.out)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
fun main(args: Array<String>) {
|
||||||
|
val exitCode = CommandLine(PartnerCtl()).execute(*args)
|
||||||
|
exitProcess(exitCode)
|
||||||
|
}
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
package work.slhaf.partner.ctl.commands
|
||||||
|
|
||||||
|
import org.jline.reader.EndOfFileException
|
||||||
|
import org.jline.reader.LineReaderBuilder
|
||||||
|
import org.jline.reader.UserInterruptException
|
||||||
|
import org.jline.terminal.Terminal
|
||||||
|
import org.jline.terminal.TerminalBuilder
|
||||||
|
import picocli.CommandLine
|
||||||
|
|
||||||
|
@CommandLine.Command(
|
||||||
|
name = "chat",
|
||||||
|
description = ["Start an interactive chat demo."]
|
||||||
|
)
|
||||||
|
class ChatCommand : Runnable {
|
||||||
|
|
||||||
|
override fun run() {
|
||||||
|
val terminal = createTerminal()
|
||||||
|
val reader = LineReaderBuilder.builder()
|
||||||
|
.terminal(terminal)
|
||||||
|
.build()
|
||||||
|
|
||||||
|
terminal.writer().println("Partner chat demo. Type /exit to quit.")
|
||||||
|
terminal.writer().flush()
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
val line = try {
|
||||||
|
reader.readLine("partner> ")
|
||||||
|
} catch (_: UserInterruptException) {
|
||||||
|
terminal.writer().println()
|
||||||
|
terminal.writer().flush()
|
||||||
|
continue
|
||||||
|
} catch (_: EndOfFileException) {
|
||||||
|
terminal.writer().println()
|
||||||
|
terminal.writer().flush()
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
when {
|
||||||
|
line == "/exit" -> break
|
||||||
|
line.isBlank() -> continue
|
||||||
|
else -> {
|
||||||
|
terminal.writer().println("echo: $line")
|
||||||
|
terminal.writer().flush()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun createTerminal(): Terminal {
|
||||||
|
return TerminalBuilder.builder()
|
||||||
|
.system(true)
|
||||||
|
.dumb(true)
|
||||||
|
.build()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package work.slhaf.partner.ctl.commands
|
||||||
|
|
||||||
|
import picocli.CommandLine
|
||||||
|
|
||||||
|
@CommandLine.Command(name = "config")
|
||||||
|
class ConfigCommand : Runnable{
|
||||||
|
override fun run() {
|
||||||
|
TODO("Not yet implemented")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package work.slhaf.partner.ctl.commands
|
||||||
|
|
||||||
|
import picocli.CommandLine
|
||||||
|
|
||||||
|
@CommandLine.Command(name = "init")
|
||||||
|
class InitCommand : Runnable{
|
||||||
|
override fun run() {
|
||||||
|
println("init ok")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package work.slhaf.partner.ctl.commands
|
||||||
|
|
||||||
|
import picocli.CommandLine
|
||||||
|
|
||||||
|
@CommandLine.Command(name = "module")
|
||||||
|
class ModuleCommand : Runnable{
|
||||||
|
override fun run() {
|
||||||
|
TODO("Not yet implemented")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package work.slhaf.partner.ctl.commands
|
||||||
|
|
||||||
|
import picocli.CommandLine
|
||||||
|
|
||||||
|
@CommandLine.Command(name = "run")
|
||||||
|
class RunCommand : Runnable{
|
||||||
|
override fun run() {
|
||||||
|
TODO("Not yet implemented")
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user