From 0f50f98a95519ff3be27e873bae630cc3da7057e Mon Sep 17 00:00:00 2001 From: Snider Date: Tue, 17 Mar 2026 02:21:52 +0000 Subject: [PATCH] fix: defer i18n.T() for package-level command vars Package-level var declarations run at import time, before i18n is initialised. Move Short/Long assignment to AddCommands functions which run after Core startup. Co-Authored-By: Virgil --- cmd/deploy/cmd_commands.go | 4 +++- cmd/deploy/cmd_deploy.go | 9 ++++++--- cmd/docs/cmd_commands.go | 8 ++++++-- cmd/docs/cmd_docs.go | 13 ++++++++++--- cmd/docs/cmd_list.go | 4 +--- cmd/docs/cmd_sync.go | 4 +--- cmd/setup/cmd_commands.go | 6 +++++- cmd/setup/cmd_setup.go | 4 +--- 8 files changed, 33 insertions(+), 19 deletions(-) diff --git a/cmd/deploy/cmd_commands.go b/cmd/deploy/cmd_commands.go index 193865f..f4fb5d6 100644 --- a/cmd/deploy/cmd_commands.go +++ b/cmd/deploy/cmd_commands.go @@ -2,13 +2,15 @@ package deploy import ( "forge.lthn.ai/core/cli/pkg/cli" + "forge.lthn.ai/core/go-devops/locales" ) func init() { - cli.RegisterCommands(AddDeployCommands) + cli.RegisterCommands(AddDeployCommands, locales.FS) } // AddDeployCommands registers the 'deploy' command and all subcommands. func AddDeployCommands(root *cli.Command) { + setDeployI18n() root.AddCommand(Cmd) } diff --git a/cmd/deploy/cmd_deploy.go b/cmd/deploy/cmd_deploy.go index 7b962dd..7e26800 100644 --- a/cmd/deploy/cmd_deploy.go +++ b/cmd/deploy/cmd_deploy.go @@ -20,9 +20,12 @@ var ( // Cmd is the root deploy command. var Cmd = &cli.Command{ - Use: "deploy", - Short: i18n.T("cmd.deploy.short"), - Long: i18n.T("cmd.deploy.long"), + Use: "deploy", +} + +func setDeployI18n() { + Cmd.Short = i18n.T("cmd.deploy.short") + Cmd.Long = i18n.T("cmd.deploy.long") } var serversCmd = &cli.Command{ diff --git a/cmd/docs/cmd_commands.go b/cmd/docs/cmd_commands.go index 4254325..31d469e 100644 --- a/cmd/docs/cmd_commands.go +++ b/cmd/docs/cmd_commands.go @@ -8,13 +8,17 @@ // to a central location for unified documentation builds. package docs -import "forge.lthn.ai/core/cli/pkg/cli" +import ( + "forge.lthn.ai/core/cli/pkg/cli" + "forge.lthn.ai/core/go-devops/locales" +) func init() { - cli.RegisterCommands(AddDocsCommands) + cli.RegisterCommands(AddDocsCommands, locales.FS) } // AddDocsCommands registers the 'docs' command and all subcommands. func AddDocsCommands(root *cli.Command) { + setDocsI18n() root.AddCommand(docsCmd) } diff --git a/cmd/docs/cmd_docs.go b/cmd/docs/cmd_docs.go index 04c6c51..fa9a709 100644 --- a/cmd/docs/cmd_docs.go +++ b/cmd/docs/cmd_docs.go @@ -19,9 +19,16 @@ var ( ) var docsCmd = &cli.Command{ - Use: "docs", - Short: i18n.T("cmd.docs.short"), - Long: i18n.T("cmd.docs.long"), + Use: "docs", +} + +func setDocsI18n() { + docsCmd.Short = i18n.T("cmd.docs.short") + docsCmd.Long = i18n.T("cmd.docs.long") + docsListCmd.Short = i18n.T("cmd.docs.list.short") + docsListCmd.Long = i18n.T("cmd.docs.list.long") + docsSyncCmd.Short = i18n.T("cmd.docs.sync.short") + docsSyncCmd.Long = i18n.T("cmd.docs.sync.long") } func init() { diff --git a/cmd/docs/cmd_list.go b/cmd/docs/cmd_list.go index a384c98..b4d565f 100644 --- a/cmd/docs/cmd_list.go +++ b/cmd/docs/cmd_list.go @@ -11,9 +11,7 @@ import ( var docsListRegistryPath string var docsListCmd = &cli.Command{ - Use: "list", - Short: i18n.T("cmd.docs.list.short"), - Long: i18n.T("cmd.docs.list.long"), + Use: "list", RunE: func(cmd *cli.Command, args []string) error { return runDocsList(docsListRegistryPath) }, diff --git a/cmd/docs/cmd_sync.go b/cmd/docs/cmd_sync.go index 5bcaa54..0b0c94e 100644 --- a/cmd/docs/cmd_sync.go +++ b/cmd/docs/cmd_sync.go @@ -21,9 +21,7 @@ var ( ) var docsSyncCmd = &cli.Command{ - Use: "sync", - Short: i18n.T("cmd.docs.sync.short"), - Long: i18n.T("cmd.docs.sync.long"), + Use: "sync", RunE: func(cmd *cli.Command, args []string) error { return runDocsSync(docsSyncRegistryPath, docsSyncOutputDir, docsSyncDryRun, docsSyncTarget) }, diff --git a/cmd/setup/cmd_commands.go b/cmd/setup/cmd_commands.go index 0f61918..3c095c8 100644 --- a/cmd/setup/cmd_commands.go +++ b/cmd/setup/cmd_commands.go @@ -25,13 +25,17 @@ package setup import ( "forge.lthn.ai/core/cli/pkg/cli" + "forge.lthn.ai/core/go-devops/locales" + "forge.lthn.ai/core/go-i18n" ) func init() { - cli.RegisterCommands(AddSetupCommands) + cli.RegisterCommands(AddSetupCommands, locales.FS) } // AddSetupCommands registers the 'setup' command and all subcommands. func AddSetupCommands(root *cli.Command) { + setupCmd.Short = i18n.T("cmd.setup.short") + setupCmd.Long = i18n.T("cmd.setup.long") AddSetupCommand(root) } diff --git a/cmd/setup/cmd_setup.go b/cmd/setup/cmd_setup.go index d933cb4..4cb81f9 100644 --- a/cmd/setup/cmd_setup.go +++ b/cmd/setup/cmd_setup.go @@ -33,9 +33,7 @@ var ( ) var setupCmd = &cli.Command{ - Use: "setup", - Short: i18n.T("cmd.setup.short"), - Long: i18n.T("cmd.setup.long"), + Use: "setup", RunE: func(cmd *cli.Command, args []string) error { return runSetupOrchestrator(registryPath, only, dryRun, all, name, build) },