From 4547cf25797cb96fb7adc98de401700f47ed28bc Mon Sep 17 00:00:00 2001 From: decentral1se Date: Wed, 3 Sep 2025 08:53:08 +0200 Subject: [PATCH] fix: help/version override for translation See https://git.coopcloud.tech/toolshed/abra/issues/628 --- cli/internal/cli.go | 2 + cli/run.go | 40 ++++++++++++++++++ pkg/i18n/locales/abra.pot | 85 +++++++++++++++++++++++++++----------- pkg/i18n/locales/es.po | 87 ++++++++++++++++++++++++++++----------- 4 files changed, 168 insertions(+), 46 deletions(-) diff --git a/cli/internal/cli.go b/cli/internal/cli.go index e98ddb16..3e8844d2 100644 --- a/cli/internal/cli.go +++ b/cli/internal/cli.go @@ -5,6 +5,8 @@ var ( Debug bool NoInput bool Offline bool + Help bool + Version bool // NOTE(d1): sub-command specific Chaos bool diff --git a/cli/run.go b/cli/run.go index a2540f9e..ce2358a8 100644 --- a/cli/run.go +++ b/cli/run.go @@ -47,6 +47,29 @@ Additional help topics:{{range .Commands}}{{if .IsAdditionalHelpTopicCommand}} Use "{{.CommandPath}} [command] --help" for more information about a command.{{end}} `) + + helpCmd = &cobra.Command{ + Use: i18n.G("help [command]"), + // translators: Short description for `help` command + Short: i18n.G("Help about any command"), + Long: i18n.G(`Help provides help for any command in the application. +Simply type abra help [path to command] for full details.`), + Run: func(c *cobra.Command, args []string) { + cmd, _, e := c.Root().Find(args) + if cmd == nil || e != nil { + c.Print(i18n.G("unknown help topic %#q\n", args)) + if err := c.Root().Usage(); err != nil { + log.Fatal(err) + } + } else { + cmd.InitDefaultHelpFlag() + cmd.InitDefaultVersionFlag() + if err := cmd.Help(); err != nil { + log.Fatal(err) + } + } + }, + } ) func Run(version, commit string) { @@ -122,6 +145,7 @@ Config: rootCmd.CompletionOptions.DisableDefaultCmd = true rootCmd.SetUsageTemplate(usageTemplate) + rootCmd.SetHelpCommand(helpCmd) // translators: `abra man` aliases. use a comma separated list of aliases // with no spaces in between @@ -185,6 +209,22 @@ Config: i18n.G("prefer offline & filesystem access"), ) + rootCmd.PersistentFlags().BoolVarP( + &internal.Help, + i18n.G("help"), + i18n.G("h"), + false, + i18n.G("help for abra"), + ) + + rootCmd.PersistentFlags().BoolVarP( + &internal.Version, + i18n.G("version"), + i18n.G("v"), + false, + i18n.G("version for abra"), + ) + catalogue.CatalogueCommand.AddCommand( catalogue.CatalogueGenerateCommand, catalogue.CatalogueSyncCommand, diff --git a/pkg/i18n/locales/abra.pot b/pkg/i18n/locales/abra.pot index 3302eeb5..d06d5a4a 100644 --- a/pkg/i18n/locales/abra.pot +++ b/pkg/i18n/locales/abra.pot @@ -7,7 +7,7 @@ msgid "" msgstr "Project-Id-Version: \n" "Report-Msgid-Bugs-To: EMAIL\n" - "POT-Creation-Date: 2025-09-03 00:25+0200\n" + "POT-Creation-Date: 2025-09-03 08:57+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -43,7 +43,7 @@ msgid " # fetch from recipe catalogue\n" " abra recipe fetch gitea --ssh" msgstr "" -#: ./cli/run.go:136 +#: ./cli/run.go:160 msgid " # generate the man pages into /usr/local/share/man/man1\n" " abra_path=$(which abra) # pass abra absolute path to sudo below\n" " sudo $abra_path man\n" @@ -857,7 +857,7 @@ msgid "Generate labels for the main recipe service.\n" msgstr "" #. translators: Short description for `man` command -#: ./cli/run.go:135 +#: ./cli/run.go:159 msgid "Generate manpage" msgstr "" @@ -887,6 +887,16 @@ msgstr "" msgid "HOST" msgstr "" +#. translators: Short description for `help` command +#: ./cli/run.go:54 +msgid "Help about any command" +msgstr "" + +#: ./cli/run.go:55 +msgid "Help provides help for any command in the application.\n" + "Simply type abra help [path to command] for full details." +msgstr "" + #: ./cli/app/ps.go:187 ./cli/recipe/version.go:69 msgid "IMAGE" msgstr "" @@ -1304,14 +1314,14 @@ msgid "The Co-op Cloud auto-updater πŸ€– πŸš€" msgstr "" #. translators: Short description for `abra` binary -#: ./cli/run.go:57 +#: ./cli/run.go:80 msgid "The Co-op Cloud command-line utility belt πŸŽ©πŸ‡" msgstr "" #. translators: Long description for `abra` binary. This needs to be #. translated in the same way as the Short description so that everything #. matches up -#: ./cli/run.go:61 +#: ./cli/run.go:84 #, c-format msgid "The Co-op Cloud command-line utility belt πŸŽ©πŸ‡\n" "\n" @@ -1637,7 +1647,7 @@ msgid "aborting as requested" msgstr "" #. translators: `abra` binary name -#: ./cli/run.go:55 +#: ./cli/run.go:78 msgid "abra [cmd] [args] [flags]" msgstr "" @@ -1645,7 +1655,7 @@ msgstr "" msgid "abra app labels 1312.net" msgstr "" -#: ./cli/run.go:114 +#: ./cli/run.go:137 #, c-format msgid "abra version: %s, commit: %s, lang: %s" msgstr "" @@ -1721,7 +1731,7 @@ msgid "ambiguous service list received, prompting for input" msgstr "" #. translators: `abra app` command for autocompletion -#: ./cli/run.go:68 +#: ./cli/run.go:91 msgid "app" msgstr "" @@ -1779,7 +1789,7 @@ msgid "attempting to scale %s to 1" msgstr "" #. translators: `abra autocomplete` command for autocompletion -#: ./cli/run.go:70 +#: ./cli/run.go:93 msgid "autocomplete" msgstr "" @@ -1955,7 +1965,7 @@ msgid "cannot use [version] and --latest together" msgstr "" #. translators: `abra catalogue` command for autocompletion -#: ./cli/run.go:72 +#: ./cli/run.go:95 msgid "catalogue" msgstr "" @@ -2438,7 +2448,7 @@ msgstr "" msgid "domain name for app" msgstr "" -#: ./cli/run.go:160 +#: ./cli/run.go:184 msgid "don't forget to run 'sudo mandb'" msgstr "" @@ -3055,6 +3065,10 @@ msgstr "" msgid "git: opening repository in %s" msgstr "" +#: ./cli/run.go:215 +msgid "h" +msgstr "" + #: ./cli/recipe/new.go:94 msgid "happy hacking πŸŽ‰" msgstr "" @@ -3071,6 +3085,18 @@ msgstr "" msgid "healthcheck enabled for all services" msgstr "" +#: ./cli/run.go:214 +msgid "help" +msgstr "" + +#: ./cli/run.go:52 +msgid "help [command]" +msgstr "" + +#: ./cli/run.go:217 +msgid "help for abra" +msgstr "" + #: ./cli/app/restore.go:129 msgid "hooks" msgstr "" @@ -3411,7 +3437,7 @@ msgstr "" #. with no spaces in between #. translators: `abra man` aliases. use a comma separated list of aliases #. with no spaces in between -#: ./cli/app/list.go:318 ./cli/app/move.go:34 ./cli/app/ps.go:205 ./cli/app/secret.go:553 ./cli/app/secret.go:649 ./cli/recipe/list.go:104 ./cli/recipe/upgrade.go:376 ./cli/recipe/version.go:139 ./cli/run.go:128 ./cli/server/list.go:106 ./cli/updater/updater.go:560 +#: ./cli/app/list.go:318 ./cli/app/move.go:34 ./cli/app/ps.go:205 ./cli/app/secret.go:553 ./cli/app/secret.go:649 ./cli/recipe/list.go:104 ./cli/recipe/upgrade.go:376 ./cli/recipe/version.go:139 ./cli/run.go:152 ./cli/server/list.go:106 ./cli/updater/updater.go:560 msgid "m" msgstr "" @@ -3434,12 +3460,12 @@ msgid "malformed version pin specification: %s" msgstr "" #. translators: `abra man` command for autocompletion -#: ./cli/run.go:74 +#: ./cli/run.go:97 msgid "man" msgstr "" #. translators: `man` command -#: ./cli/run.go:132 +#: ./cli/run.go:156 msgid "man [flags]" msgstr "" @@ -3918,7 +3944,7 @@ msgstr "" msgid "polling undeploy status" msgstr "" -#: ./cli/run.go:185 +#: ./cli/run.go:209 msgid "prefer offline & filesystem access" msgstr "" @@ -4054,7 +4080,7 @@ msgid "readme: %s, " msgstr "" #. translators: `abra recipe` command for autocompletion -#: ./cli/app/list.go:302 ./cli/app/list.go:309 ./cli/run.go:76 +#: ./cli/app/list.go:302 ./cli/app/list.go:309 ./cli/run.go:99 msgid "recipe" msgstr "" @@ -4496,7 +4522,7 @@ msgid "secrets are %s shown again, please save them %s" msgstr "" #. translators: `abra server` command for autocompletion -#: ./cli/app/list.go:325 ./cli/app/list.go:332 ./cli/app/new.go:337 ./cli/app/new.go:344 ./cli/run.go:78 +#: ./cli/app/list.go:325 ./cli/app/list.go:332 ./cli/app/new.go:337 ./cli/app/new.go:344 ./cli/run.go:101 msgid "server" msgstr "" @@ -4612,7 +4638,7 @@ msgstr "" msgid "show apps of a specific server" msgstr "" -#: ./cli/run.go:169 ./cli/updater/updater.go:507 +#: ./cli/run.go:193 ./cli/updater/updater.go:507 msgid "show debug messages" msgstr "" @@ -4893,7 +4919,7 @@ msgstr "" msgid "tmpfs options are incompatible with type volume" msgstr "" -#: ./cli/run.go:177 ./cli/updater/updater.go:515 +#: ./cli/run.go:201 ./cli/updater/updater.go:515 msgid "toggle non-interactive mode" msgstr "" @@ -4977,7 +5003,7 @@ msgstr "" msgid "unable to convert to JSON: %s" msgstr "" -#: ./cli/run.go:94 +#: ./cli/run.go:117 #, c-format msgid "unable to create %s: %s" msgstr "" @@ -5071,7 +5097,7 @@ msgstr "" msgid "unable to parse '%s' value as bool: %s" msgstr "" -#: ./cli/run.go:152 +#: ./cli/run.go:176 #, c-format msgid "unable to proceed, %s does not exist?" msgstr "" @@ -5227,6 +5253,11 @@ msgstr "" msgid "unknown deployed version, unable to upgrade" msgstr "" +#: ./cli/run.go:60 +#, c-format +msgid "unknown help topic %#q\n" +msgstr "" + #: ./pkg/upstream/convert/service.go:780 #, c-format msgid "unknown mode: %s" @@ -5268,7 +5299,7 @@ msgid "updating %s to %s in %s" msgstr "" #. translators: `abra upgrade` command for autocompletion -#: ./cli/run.go:80 +#: ./cli/run.go:103 msgid "upgrade" msgstr "" @@ -5343,7 +5374,7 @@ msgstr "" #. translators: `abra recipe versions` aliases. use a comma separated list of aliases #. with no spaces in between -#: ./cli/app/backup.go:311 ./cli/app/restore.go:122 ./cli/recipe/version.go:19 ./cli/server/prune.go:107 +#: ./cli/app/backup.go:311 ./cli/app/restore.go:122 ./cli/recipe/version.go:19 ./cli/run.go:223 ./cli/server/prune.go:107 msgid "v" msgstr "" @@ -5371,6 +5402,10 @@ msgstr "" msgid "vendor config versions in an abra.sh" msgstr "" +#: ./cli/run.go:222 +msgid "version" +msgstr "" + #: ./pkg/app/app.go:688 #, c-format msgid "version %s saved to %s.env" @@ -5381,6 +5416,10 @@ msgstr "" msgid "version : %s, " msgstr "" +#: ./cli/run.go:225 +msgid "version for abra" +msgstr "" + #: ./pkg/recipe/recipe.go:130 #, c-format msgid "version seems invalid: %s" diff --git a/pkg/i18n/locales/es.po b/pkg/i18n/locales/es.po index 22d5e8d4..07deeebb 100644 --- a/pkg/i18n/locales/es.po +++ b/pkg/i18n/locales/es.po @@ -2,7 +2,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: EMAIL\n" -"POT-Creation-Date: 2025-09-03 00:25+0200\n" +"POT-Creation-Date: 2025-09-03 08:57+0200\n" "PO-Revision-Date: 2025-08-29 21:45+0000\n" "Last-Translator: chasqui \n" "Language-Team: Spanish