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:
@ -3,7 +3,6 @@ package app
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"path"
|
||||
@ -15,6 +14,7 @@ import (
|
||||
"coopcloud.tech/abra/pkg/client"
|
||||
containerPkg "coopcloud.tech/abra/pkg/container"
|
||||
"coopcloud.tech/abra/pkg/formatter"
|
||||
"coopcloud.tech/abra/pkg/i18n"
|
||||
"coopcloud.tech/abra/pkg/log"
|
||||
"coopcloud.tech/abra/pkg/upstream/container"
|
||||
"github.com/docker/cli/cli/command"
|
||||
@ -26,14 +26,14 @@ import (
|
||||
)
|
||||
|
||||
var AppCpCommand = &cobra.Command{
|
||||
Use: "cp <domain> <src> <dst> [flags]",
|
||||
Aliases: []string{"c"},
|
||||
Short: "Copy files to/from a deployed app service",
|
||||
Example: ` # copy myfile.txt to the root of the app service
|
||||
Use: i18n.G("cp <domain> <src> <dst> [flags]"),
|
||||
Aliases: []string{i18n.G("c")},
|
||||
Short: i18n.G("Copy files to/from a deployed app service"),
|
||||
Example: i18n.G(` # copy myfile.txt to the root of the app service
|
||||
abra app cp 1312.net myfile.txt app:/
|
||||
|
||||
# copy that file back to your current working directory locally
|
||||
abra app cp 1312.net app:/myfile.txt ./`,
|
||||
abra app cp 1312.net app:/myfile.txt ./`),
|
||||
Args: cobra.ExactArgs(3),
|
||||
ValidArgsFunction: func(
|
||||
cmd *cobra.Command,
|
||||
@ -69,7 +69,7 @@ var AppCpCommand = &cobra.Command{
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
log.Debugf("retrieved %s as target container on %s", formatter.ShortenID(container.ID), app.Server)
|
||||
log.Debug(i18n.G("retrieved %s as target container on %s", formatter.ShortenID(container.ID), app.Server))
|
||||
|
||||
if toContainer {
|
||||
err = CopyToContainer(cl, container.ID, srcPath, dstPath)
|
||||
@ -82,7 +82,7 @@ var AppCpCommand = &cobra.Command{
|
||||
},
|
||||
}
|
||||
|
||||
var errServiceMissing = errors.New("one of <src>/<dest> arguments must take $SERVICE:$PATH form")
|
||||
var errServiceMissing = errors.New(i18n.G("one of <src>/<dest> arguments must take $SERVICE:$PATH form"))
|
||||
|
||||
// parseSrcAndDst parses src and dest string. One of src or dst must be of the form $SERVICE:$PATH
|
||||
func parseSrcAndDst(src, dst string) (srcPath string, dstPath string, service string, toContainer bool, err error) {
|
||||
@ -105,7 +105,7 @@ func parseSrcAndDst(src, dst string) (srcPath string, dstPath string, service st
|
||||
func CopyToContainer(cl *dockerClient.Client, containerID, srcPath, dstPath string) error {
|
||||
srcStat, err := os.Stat(srcPath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("local %s ", err)
|
||||
return errors.New(i18n.G("local %s ", err))
|
||||
}
|
||||
|
||||
dstStat, err := cl.ContainerStatPath(context.Background(), containerID, dstPath)
|
||||
@ -114,7 +114,7 @@ func CopyToContainer(cl *dockerClient.Client, containerID, srcPath, dstPath stri
|
||||
if errdefs.IsNotFound(err) {
|
||||
dstExists = false
|
||||
} else {
|
||||
return fmt.Errorf("remote path: %s", err)
|
||||
return errors.New(i18n.G("remote path: %s", err))
|
||||
}
|
||||
}
|
||||
|
||||
@ -142,7 +142,7 @@ func CopyToContainer(cl *dockerClient.Client, containerID, srcPath, dstPath stri
|
||||
Detach: false,
|
||||
Tty: true,
|
||||
}); err != nil {
|
||||
return fmt.Errorf("create remote directory: %s", err)
|
||||
return errors.New(i18n.G("create remote directory: %s", err))
|
||||
}
|
||||
case CopyModeFileToFile:
|
||||
// Remove the file component from the path, since docker can only copy
|
||||
@ -161,7 +161,7 @@ func CopyToContainer(cl *dockerClient.Client, containerID, srcPath, dstPath stri
|
||||
return err
|
||||
}
|
||||
|
||||
log.Debugf("copy %s from local to %s on container", srcPath, dstPath)
|
||||
log.Debug(i18n.G("copy %s from local to %s on container", srcPath, dstPath))
|
||||
copyOpts := containertypes.CopyToContainerOptions{AllowOverwriteDirWithFile: false, CopyUIDGID: false}
|
||||
if err := cl.CopyToContainer(context.Background(), containerID, dstPath, content, copyOpts); err != nil {
|
||||
return err
|
||||
@ -181,7 +181,7 @@ func CopyToContainer(cl *dockerClient.Client, containerID, srcPath, dstPath stri
|
||||
Detach: false,
|
||||
Tty: true,
|
||||
}); err != nil {
|
||||
return fmt.Errorf("create remote directory: %s", err)
|
||||
return errors.New(i18n.G("create remote directory: %s", err))
|
||||
}
|
||||
}
|
||||
|
||||
@ -194,9 +194,9 @@ func CopyFromContainer(cl *dockerClient.Client, containerID, srcPath, dstPath st
|
||||
srcStat, err := cl.ContainerStatPath(context.Background(), containerID, srcPath)
|
||||
if err != nil {
|
||||
if errdefs.IsNotFound(err) {
|
||||
return fmt.Errorf("remote: %s does not exist", srcPath)
|
||||
return errors.New(i18n.G("remote: %s does not exist", srcPath))
|
||||
} else {
|
||||
return fmt.Errorf("remote path: %s", err)
|
||||
return errors.New(i18n.G("remote path: %s", err))
|
||||
}
|
||||
}
|
||||
|
||||
@ -207,7 +207,7 @@ func CopyFromContainer(cl *dockerClient.Client, containerID, srcPath, dstPath st
|
||||
if os.IsNotExist(err) {
|
||||
dstExists = false
|
||||
} else {
|
||||
return fmt.Errorf("remote path: %s", err)
|
||||
return errors.New(i18n.G("remote path: %s", err))
|
||||
}
|
||||
} else {
|
||||
dstMode = dstStat.Mode()
|
||||
@ -242,7 +242,7 @@ func CopyFromContainer(cl *dockerClient.Client, containerID, srcPath, dstPath st
|
||||
|
||||
content, _, err := cl.CopyFromContainer(context.Background(), containerID, srcPath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("copy: %s", err)
|
||||
return errors.New(i18n.G("copy: %s", err))
|
||||
}
|
||||
defer content.Close()
|
||||
if err := archive.Untar(content, dstPath, &archive.TarOptions{
|
||||
@ -250,7 +250,7 @@ func CopyFromContainer(cl *dockerClient.Client, containerID, srcPath, dstPath st
|
||||
Compression: archive.Gzip,
|
||||
NoLchown: true,
|
||||
}); err != nil {
|
||||
return fmt.Errorf("untar: %s", err)
|
||||
return errors.New(i18n.G("untar: %s", err))
|
||||
}
|
||||
|
||||
if moveDstFile != "" {
|
||||
@ -269,8 +269,8 @@ func CopyFromContainer(cl *dockerClient.Client, containerID, srcPath, dstPath st
|
||||
}
|
||||
|
||||
var (
|
||||
ErrCopyDirToFile = fmt.Errorf("can't copy dir to file")
|
||||
ErrDstDirNotExist = fmt.Errorf("destination directory does not exist")
|
||||
ErrCopyDirToFile = errors.New(i18n.G("can't copy dir to file"))
|
||||
ErrDstDirNotExist = errors.New(i18n.G("destination directory does not exist"))
|
||||
)
|
||||
|
||||
type CopyMode int
|
||||
@ -375,9 +375,9 @@ func moveFile(sourcePath, destPath string) error {
|
||||
func init() {
|
||||
AppCpCommand.Flags().BoolVarP(
|
||||
&internal.Chaos,
|
||||
"chaos",
|
||||
"C",
|
||||
i18n.G("chaos"),
|
||||
i18n.G("C"),
|
||||
false,
|
||||
"ignore uncommitted recipes changes",
|
||||
i18n.G("ignore uncommitted recipes changes"),
|
||||
)
|
||||
}
|
||||
|
Reference in New Issue
Block a user