WIP: feat: translation support
Some checks failed
continuous-integration/drone/push Build is failing

See #483
This commit is contained in:
2025-08-19 11:22:52 +02:00
parent 5cf6048ecb
commit d9cffbe6d1
68 changed files with 735 additions and 729 deletions

View File

@ -13,14 +13,15 @@ import (
"coopcloud.tech/abra/pkg/log"
"coopcloud.tech/abra/pkg/server"
sshPkg "coopcloud.tech/abra/pkg/ssh"
"github.com/leonelquinteros/gotext"
"github.com/spf13/cobra"
)
var ServerAddCommand = &cobra.Command{
Use: "add [[server] | --local] [flags]",
Use: gotext.Get("add [[server] | --local] [flags]"),
Aliases: []string{"a"},
Short: "Add a new server",
Long: `Add a new server to your configuration so that it can be managed by Abra.
Short: gotext.Get("Add a new server"),
Long: gotext.Get(`Add a new server to your configuration so that it can be managed by Abra.
Abra relies on the standard SSH command-line and ~/.ssh/config for client
connection details. You must configure an entry per-host in your ~/.ssh/config
@ -35,8 +36,8 @@ for each server:
If "--local" is passed, then Abra assumes that the current local server is
intended as the target server. This is useful when you want to have your entire
Co-op Cloud config located on the server itself, and not on your local
developer machine. The domain is then set to "default".`,
Example: " abra server add 1312.net",
developer machine. The domain is then set to "default".`),
Example: gotext.Get(" abra server add 1312.net"),
Args: cobra.RangeArgs(0, 1),
ValidArgsFunction: func(
cmd *cobra.Command,
@ -49,11 +50,11 @@ developer machine. The domain is then set to "default".`,
},
Run: func(cmd *cobra.Command, args []string) {
if len(args) > 0 && local {
log.Fatal("cannot use [server] and --local together")
log.Fatal(gotext.Get("cannot use [server] and --local together"))
}
if len(args) == 0 && !local {
log.Fatal("missing argument or --local/-l flag")
log.Fatal(gotext.Get("missing argument or --local/-l flag"))
}
name := "default"
@ -72,7 +73,7 @@ developer machine. The domain is then set to "default".`,
log.Fatal(err)
}
log.Debugf("attempting to create client for %s", name)
log.Debug(gotext.Get("attempting to create client for %s", name))
if _, err := client.New(name, timeout); err != nil {
cleanUp(name)
@ -80,9 +81,9 @@ developer machine. The domain is then set to "default".`,
}
if created {
log.Info("local server successfully added")
log.Info(gotext.Get("local server successfully added"))
} else {
log.Warn("local server already exists")
log.Warn(gotext.Get("local server already exists"))
}
return
@ -96,27 +97,27 @@ developer machine. The domain is then set to "default".`,
created, err := newContext(name)
if err != nil {
cleanUp(name)
log.Fatalf("unable to create local context: %s", err)
log.Fatal(gotext.Get("unable to create local context: %s", err))
}
log.Debugf("attempting to create client for %s", name)
log.Debug(gotext.Get("attempting to create client for %s", name))
if _, err := client.New(name, timeout); err != nil {
cleanUp(name)
log.Fatalf("ssh %s error: %s", name, sshPkg.Fatal(name, err))
log.Fatal(gotext.Get("ssh %s error: %s", name, sshPkg.Fatal(name, err)))
}
if created {
log.Infof("%s successfully added", name)
log.Info(gotext.Get("%s successfully added", name))
if _, err := dns.EnsureIPv4(name); err != nil {
log.Warnf("unable to resolve IPv4 for %s", name)
log.Warn(gotext.Get("unable to resolve IPv4 for %s", name))
}
return
}
log.Warnf("%s already exists", name)
log.Warn(gotext.Get("%s already exists", name))
},
}
@ -124,7 +125,7 @@ developer machine. The domain is then set to "default".`,
// "server add" attempt.
func cleanUp(name string) {
if name != "default" {
log.Debugf("serverAdd: cleanUp: cleaning up context for %s", name)
log.Debug(gotext.Get("serverAdd: cleanUp: cleaning up context for %s", name))
if err := client.DeleteContext(name); err != nil {
log.Fatal(err)
}
@ -133,16 +134,16 @@ func cleanUp(name string) {
serverDir := filepath.Join(config.SERVERS_DIR, name)
files, err := config.GetAllFilesInDirectory(serverDir)
if err != nil {
log.Fatalf("serverAdd: cleanUp: unable to list files in %s: %s", serverDir, err)
log.Fatal(gotext.Get("serverAdd: cleanUp: unable to list files in %s: %s", serverDir, err))
}
if len(files) > 0 {
log.Debugf("serverAdd: cleanUp: %s is not empty, aborting cleanup", serverDir)
log.Debug(gotext.Get("serverAdd: cleanUp: %s is not empty, aborting cleanup", serverDir))
return
}
if err := os.RemoveAll(serverDir); err != nil {
log.Fatalf("serverAdd: cleanUp: failed to remove %s: %s", serverDir, err)
log.Fatal(gotext.Get("serverAdd: cleanUp: failed to remove %s: %s", serverDir, err))
}
}
@ -159,12 +160,12 @@ func newContext(name string) (bool, error) {
for _, context := range contexts {
if context.Name == name {
log.Debugf("context for %s already exists", name)
log.Debug(gotext.Get("context for %s already exists", name))
return false, nil
}
}
log.Debugf("creating context with domain %s", name)
log.Debugf(gotext.Get("creating context with domain %s", name))
if err := client.CreateContext(name); err != nil {
return false, nil
@ -180,7 +181,7 @@ func createServerDir(name string) (bool, error) {
return false, err
}
log.Debugf("server dir for %s already created", name)
log.Debug(gotext.Get("server dir for %s already created", name))
return false, nil
}
@ -198,6 +199,6 @@ func init() {
"local",
"l",
false,
"use local server",
gotext.Get("use local server"),
)
}