From 442397c1f5124941a50b964b8557a8e7001c4917 Mon Sep 17 00:00:00 2001 From: slhafzjw Date: Wed, 6 May 2026 14:55:16 +0800 Subject: [PATCH] feat(partnerctl): i18n-ize command and option descriptions via message bundles --- .../java/work/slhaf/partner/ctl/PartnerCtl.kt | 5 +++-- .../slhaf/partner/ctl/commands/ChatCommand.kt | 3 ++- .../slhaf/partner/ctl/commands/ConfigCommand.kt | 6 +++++- .../slhaf/partner/ctl/commands/InitCommand.kt | 6 +++++- .../slhaf/partner/ctl/commands/LogCommand.kt | 16 +++++++++++++--- .../slhaf/partner/ctl/commands/ModuleCommand.kt | 6 +++++- .../slhaf/partner/ctl/commands/RunCommand.kt | 11 +++++++++-- .../partner/ctl/commands/ShutdownCommand.kt | 10 +++++++--- .../src/main/resources/i18n/messages.properties | 14 ++++++++++++++ .../resources/i18n/messages_zh_CN.properties | 14 ++++++++++++++ 10 files changed, 77 insertions(+), 14 deletions(-) diff --git a/PartnerCtl/src/main/java/work/slhaf/partner/ctl/PartnerCtl.kt b/PartnerCtl/src/main/java/work/slhaf/partner/ctl/PartnerCtl.kt index 5cce8dcc..2ec4eb5b 100644 --- a/PartnerCtl/src/main/java/work/slhaf/partner/ctl/PartnerCtl.kt +++ b/PartnerCtl/src/main/java/work/slhaf/partner/ctl/PartnerCtl.kt @@ -9,6 +9,8 @@ import kotlin.system.exitProcess @CommandLine.Command( name = "partnerctl", + resourceBundle = "i18n.messages", + description = [$$"${bundle:cli.partnerctl.description}"], mixinStandardHelpOptions = true, version = ["partnerctl 0.1.0"], subcommands = [ @@ -20,8 +22,7 @@ import kotlin.system.exitProcess ConfigCommand::class, ModuleCommand::class, AutoComplete.GenerateCompletion::class - ], - description = ["Partner command line tool."] + ] ) class PartnerCtl : Runnable { diff --git a/PartnerCtl/src/main/java/work/slhaf/partner/ctl/commands/ChatCommand.kt b/PartnerCtl/src/main/java/work/slhaf/partner/ctl/commands/ChatCommand.kt index fe26381a..6f663a5a 100644 --- a/PartnerCtl/src/main/java/work/slhaf/partner/ctl/commands/ChatCommand.kt +++ b/PartnerCtl/src/main/java/work/slhaf/partner/ctl/commands/ChatCommand.kt @@ -9,7 +9,8 @@ import picocli.CommandLine @CommandLine.Command( name = "chat", - description = ["Start an interactive chat demo."] + resourceBundle = "i18n.messages", + description = [$$"${bundle:cli.chat.description}"], ) class ChatCommand : Runnable { diff --git a/PartnerCtl/src/main/java/work/slhaf/partner/ctl/commands/ConfigCommand.kt b/PartnerCtl/src/main/java/work/slhaf/partner/ctl/commands/ConfigCommand.kt index 7a354aab..f7cdcfa2 100644 --- a/PartnerCtl/src/main/java/work/slhaf/partner/ctl/commands/ConfigCommand.kt +++ b/PartnerCtl/src/main/java/work/slhaf/partner/ctl/commands/ConfigCommand.kt @@ -2,7 +2,11 @@ package work.slhaf.partner.ctl.commands import picocli.CommandLine -@CommandLine.Command(name = "config") +@CommandLine.Command( + name = "config", + resourceBundle = "i18n.messages", + description = [$$"${bundle:cli.config.description}"], +) class ConfigCommand : Runnable{ override fun run() { TODO("Not yet implemented") diff --git a/PartnerCtl/src/main/java/work/slhaf/partner/ctl/commands/InitCommand.kt b/PartnerCtl/src/main/java/work/slhaf/partner/ctl/commands/InitCommand.kt index 0da6b09c..7f4ea86c 100644 --- a/PartnerCtl/src/main/java/work/slhaf/partner/ctl/commands/InitCommand.kt +++ b/PartnerCtl/src/main/java/work/slhaf/partner/ctl/commands/InitCommand.kt @@ -20,7 +20,11 @@ import java.nio.file.Files import java.nio.file.Path import java.nio.file.Paths -@CommandLine.Command(name = "init", description = ["Initialize partner agent."]) +@CommandLine.Command( + name = "init", + resourceBundle = "i18n.messages", + description = [$$"${bundle:cli.init.description}"], +) class InitCommand : Runnable { lateinit var home: Path diff --git a/PartnerCtl/src/main/java/work/slhaf/partner/ctl/commands/LogCommand.kt b/PartnerCtl/src/main/java/work/slhaf/partner/ctl/commands/LogCommand.kt index 51bc78a3..78e4f75f 100644 --- a/PartnerCtl/src/main/java/work/slhaf/partner/ctl/commands/LogCommand.kt +++ b/PartnerCtl/src/main/java/work/slhaf/partner/ctl/commands/LogCommand.kt @@ -7,13 +7,23 @@ import work.slhaf.partner.ctl.i18n.I18n.text import java.nio.file.Files import java.nio.file.Path -@CommandLine.Command(name = "log", description = ["Show Partner logs."]) +@CommandLine.Command( + name = "log", + resourceBundle = "i18n.messages", + description = [$$"${bundle:cli.log.description}"], +) class LogCommand : Runnable { - @CommandLine.Option(names = ["--tail"], description = ["Number of log lines to show before exiting or following."]) + @CommandLine.Option( + names = ["--tail"], + descriptionKey = "cli.log.option.tail.description", + ) var tailLines: Int = 200 - @CommandLine.Option(names = ["-f", "--follow"], description = ["Follow appended log output."]) + @CommandLine.Option( + names = ["-f", "--follow"], + descriptionKey = "cli.log.option.follow.description", + ) var follow: Boolean = false override fun run() { diff --git a/PartnerCtl/src/main/java/work/slhaf/partner/ctl/commands/ModuleCommand.kt b/PartnerCtl/src/main/java/work/slhaf/partner/ctl/commands/ModuleCommand.kt index 6f1ecf63..fbcd0c07 100644 --- a/PartnerCtl/src/main/java/work/slhaf/partner/ctl/commands/ModuleCommand.kt +++ b/PartnerCtl/src/main/java/work/slhaf/partner/ctl/commands/ModuleCommand.kt @@ -2,7 +2,11 @@ package work.slhaf.partner.ctl.commands import picocli.CommandLine -@CommandLine.Command(name = "module") +@CommandLine.Command( + name = "module", + resourceBundle = "i18n.messages", + description = [$$"${bundle:cli.module.description}"], +) class ModuleCommand : Runnable{ override fun run() { TODO("Not yet implemented") diff --git a/PartnerCtl/src/main/java/work/slhaf/partner/ctl/commands/RunCommand.kt b/PartnerCtl/src/main/java/work/slhaf/partner/ctl/commands/RunCommand.kt index e215b7d5..1d3647a5 100644 --- a/PartnerCtl/src/main/java/work/slhaf/partner/ctl/commands/RunCommand.kt +++ b/PartnerCtl/src/main/java/work/slhaf/partner/ctl/commands/RunCommand.kt @@ -10,10 +10,17 @@ import java.nio.file.Path import java.nio.file.StandardOpenOption import java.time.LocalDateTime -@CommandLine.Command(name = "run", description = ["Start Partner agent."]) +@CommandLine.Command( + name = "run", + resourceBundle = "i18n.messages", + description = [$$"${bundle:cli.run.description}"], +) class RunCommand : Runnable { - @CommandLine.Option(names = ["-d", "--background"], description = ["Run Partner in background."]) + @CommandLine.Option( + names = ["-d", "--background"], + descriptionKey = "cli.run.option.background.description", + ) var background: Boolean = false override fun run() { diff --git a/PartnerCtl/src/main/java/work/slhaf/partner/ctl/commands/ShutdownCommand.kt b/PartnerCtl/src/main/java/work/slhaf/partner/ctl/commands/ShutdownCommand.kt index 78a45c31..db97f271 100644 --- a/PartnerCtl/src/main/java/work/slhaf/partner/ctl/commands/ShutdownCommand.kt +++ b/PartnerCtl/src/main/java/work/slhaf/partner/ctl/commands/ShutdownCommand.kt @@ -5,18 +5,22 @@ import work.slhaf.partner.ctl.commands.control.* import work.slhaf.partner.ctl.i18n.I18n import work.slhaf.partner.ctl.support.CommandInterrupted -@CommandLine.Command(name = "shutdown", description = ["Shutdown Partner agent."]) +@CommandLine.Command( + name = "shutdown", + resourceBundle = "i18n.messages", + description = [$$"${bundle:cli.shutdown.description}"], +) class ShutdownCommand : Runnable { @CommandLine.Option( names = ["--timeout"], - description = ["Seconds to wait after graceful termination before failing or forcing shutdown."] + descriptionKey = "cli.shutdown.option.timeout.description" ) var timeoutSeconds: Long = 10 @CommandLine.Option( names = ["-f", "--force"], - description = ["Forcefully kill matching Partner process if it does not exit before timeout."] + descriptionKey = "cli.shutdown.option.force.description" ) var force: Boolean = false diff --git a/PartnerCtl/src/main/resources/i18n/messages.properties b/PartnerCtl/src/main/resources/i18n/messages.properties index dc09c643..a8e496cd 100644 --- a/PartnerCtl/src/main/resources/i18n/messages.properties +++ b/PartnerCtl/src/main/resources/i18n/messages.properties @@ -1,3 +1,17 @@ +cli.partnerctl.description=Partner command line tool. +cli.init.description=Initialize Partner agent. +cli.run.description=Start Partner agent. +cli.run.option.background.description=Run Partner in background. +cli.shutdown.description=Shutdown Partner agent. +cli.shutdown.option.timeout.description=Seconds to wait after graceful termination before failing or forcing shutdown. +cli.shutdown.option.force.description=Forcefully kill matching Partner process if it does not exit before timeout. +cli.log.description=Show Partner logs. +cli.log.option.tail.description=Number of log lines to show before exiting or following. +cli.log.option.follow.description=Follow appended log output. +cli.chat.description=Start an interactive chat demo. +cli.config.description=Manage Partner configuration. +cli.module.description=Manage Partner modules. + init.home.section=Initialize Partner Home init.home.label=Partner Home init.home.success=Partner Home initialized at {0} diff --git a/PartnerCtl/src/main/resources/i18n/messages_zh_CN.properties b/PartnerCtl/src/main/resources/i18n/messages_zh_CN.properties index 771f084f..7f4db2b7 100644 --- a/PartnerCtl/src/main/resources/i18n/messages_zh_CN.properties +++ b/PartnerCtl/src/main/resources/i18n/messages_zh_CN.properties @@ -1,3 +1,17 @@ +cli.partnerctl.description=Partner 命令行工具。 +cli.init.description=初始化 Partner agent。 +cli.run.description=启动 Partner agent。 +cli.run.option.background.description=后台运行 Partner。 +cli.shutdown.description=停止 Partner agent。 +cli.shutdown.option.timeout.description=优雅停止后等待的秒数,超时后失败或强制停止。 +cli.shutdown.option.force.description=如果匹配的 Partner 进程没有在超时前退出,则强制结束进程。 +cli.log.description=查看 Partner 日志。 +cli.log.option.tail.description=退出或 follow 前显示的日志行数。 +cli.log.option.follow.description=持续跟随新增日志输出。 +cli.chat.description=启动交互式聊天 demo。 +cli.config.description=管理 Partner 配置。 +cli.module.description=管理 Partner 模块。 + init.home.section=初始化 Partner Home init.home.label=Partner Home init.home.success=Partner Home 已初始化:{0}