feat: translation support
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
See #483
This commit is contained in:
53
cli/run.go
53
cli/run.go
@ -1,6 +1,7 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
@ -10,6 +11,8 @@ import (
|
||||
"coopcloud.tech/abra/cli/recipe"
|
||||
"coopcloud.tech/abra/cli/server"
|
||||
"coopcloud.tech/abra/pkg/config"
|
||||
"coopcloud.tech/abra/pkg/formatter"
|
||||
"coopcloud.tech/abra/pkg/i18n"
|
||||
"coopcloud.tech/abra/pkg/log"
|
||||
charmLog "github.com/charmbracelet/log"
|
||||
"github.com/spf13/cobra"
|
||||
@ -18,19 +21,20 @@ import (
|
||||
|
||||
func Run(version, commit string) {
|
||||
rootCmd := &cobra.Command{
|
||||
Use: "abra [cmd] [args] [flags]",
|
||||
Short: "The Co-op Cloud command-line utility belt 🎩🐇",
|
||||
Use: i18n.G("abra [cmd] [args] [flags]"),
|
||||
Short: i18n.G("The Co-op Cloud command-line utility belt 🎩🐇"),
|
||||
Version: fmt.Sprintf("%s-%s", version, commit[:7]),
|
||||
ValidArgs: []string{
|
||||
"app",
|
||||
"autocomplete",
|
||||
"catalogue",
|
||||
"man",
|
||||
"recipe",
|
||||
"server",
|
||||
"upgrade",
|
||||
i18n.G("app"),
|
||||
i18n.G("autocomplete"),
|
||||
i18n.G("catalogue"),
|
||||
i18n.G("man"),
|
||||
i18n.G("recipe"),
|
||||
i18n.G("server"),
|
||||
i18n.G("upgrade"),
|
||||
},
|
||||
PersistentPreRun: func(cmd *cobra.Command, args []string) {
|
||||
|
||||
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
|
||||
dirs := []map[string]os.FileMode{
|
||||
{config.ABRA_DIR: 0764},
|
||||
{config.SERVERS_DIR: 0700},
|
||||
@ -42,7 +46,7 @@ func Run(version, commit string) {
|
||||
for path, perm := range dir {
|
||||
if err := os.Mkdir(path, perm); err != nil {
|
||||
if !os.IsExist(err) {
|
||||
log.Fatal(err)
|
||||
return errors.New(i18n.G("unable to create %s: %s", path, err))
|
||||
}
|
||||
continue
|
||||
}
|
||||
@ -62,24 +66,29 @@ func Run(version, commit string) {
|
||||
log.SetReportCaller(true)
|
||||
}
|
||||
|
||||
log.Debugf("abra version %s, commit %s", version, commit)
|
||||
log.Debug(i18n.G(
|
||||
"abra version: %s, commit: %s, lang: %s",
|
||||
version, formatter.SmallSHA(commit), i18n.Locale,
|
||||
))
|
||||
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
rootCmd.CompletionOptions.DisableDefaultCmd = true
|
||||
|
||||
manCommand := &cobra.Command{
|
||||
Use: "man [flags]",
|
||||
Use: i18n.G("man [flags]"),
|
||||
Aliases: []string{"m"},
|
||||
Short: "Generate manpage",
|
||||
Example: ` # generate the man pages into /usr/local/share/man/man1
|
||||
Short: i18n.G("Generate manpage"),
|
||||
Example: i18n.G(` # generate the man pages into /usr/local/share/man/man1
|
||||
abra_path=$(which abra) # pass abra absolute path to sudo below
|
||||
sudo $abra_path man
|
||||
sudo mandb
|
||||
|
||||
# read the man pages
|
||||
man abra
|
||||
man abra-app-deploy`,
|
||||
man abra-app-deploy`),
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
header := &doc.GenManHeader{
|
||||
Title: "ABRA",
|
||||
@ -88,7 +97,7 @@ func Run(version, commit string) {
|
||||
|
||||
manDir := "/usr/local/share/man/man1"
|
||||
if _, err := os.Stat(manDir); os.IsNotExist(err) {
|
||||
log.Fatalf("unable to proceed, '%s' does not exist?")
|
||||
log.Fatal(i18n.G("unable to proceed, %s does not exist?", manDir))
|
||||
}
|
||||
|
||||
err := doc.GenManTree(rootCmd, header, manDir)
|
||||
@ -96,7 +105,7 @@ func Run(version, commit string) {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
log.Info("don't forget to run 'sudo mandb'")
|
||||
log.Info(i18n.G("don't forget to run 'sudo mandb'"))
|
||||
},
|
||||
}
|
||||
|
||||
@ -105,7 +114,7 @@ func Run(version, commit string) {
|
||||
"debug",
|
||||
"d",
|
||||
false,
|
||||
"show debug messages",
|
||||
i18n.G("show debug messages"),
|
||||
)
|
||||
|
||||
rootCmd.PersistentFlags().BoolVarP(
|
||||
@ -113,7 +122,7 @@ func Run(version, commit string) {
|
||||
"no-input",
|
||||
"n",
|
||||
false,
|
||||
"toggle non-interactive mode",
|
||||
i18n.G("toggle non-interactive mode"),
|
||||
)
|
||||
|
||||
rootCmd.PersistentFlags().BoolVarP(
|
||||
@ -121,7 +130,7 @@ func Run(version, commit string) {
|
||||
"offline",
|
||||
"o",
|
||||
false,
|
||||
"prefer offline & filesystem access",
|
||||
i18n.G("prefer offline & filesystem access"),
|
||||
)
|
||||
|
||||
rootCmd.PersistentFlags().BoolVarP(
|
||||
@ -129,7 +138,7 @@ func Run(version, commit string) {
|
||||
"ignore-env-version",
|
||||
"i",
|
||||
false,
|
||||
"ignore .env version checkout",
|
||||
i18n.G("ignore .env version checkout"),
|
||||
)
|
||||
|
||||
catalogue.CatalogueCommand.AddCommand(
|
||||
|
Reference in New Issue
Block a user