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:
@ -13,15 +13,16 @@ import (
|
||||
appPkg "coopcloud.tech/abra/pkg/app"
|
||||
"coopcloud.tech/abra/pkg/autocomplete"
|
||||
"coopcloud.tech/abra/pkg/client"
|
||||
"coopcloud.tech/abra/pkg/i18n"
|
||||
"coopcloud.tech/abra/pkg/log"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var AppCmdCommand = &cobra.Command{
|
||||
Use: "command <domain> [service | --local] <cmd> [[args] [flags] | [flags] -- [args]]",
|
||||
Aliases: []string{"cmd"},
|
||||
Short: "Run app commands",
|
||||
Long: `Run an app specific command.
|
||||
Use: i18n.G("command <domain> [service | --local] <cmd> [[args] [flags] | [flags] -- [args]]"),
|
||||
Aliases: []string{i18n.G("cmd")},
|
||||
Short: i18n.G("Run app commands"),
|
||||
Long: i18n.G(`Run an app specific command.
|
||||
|
||||
These commands are bash functions, defined in the abra.sh of the recipe itself.
|
||||
They can be run within the context of a service (e.g. app) or locally on your
|
||||
@ -30,24 +31,24 @@ work station by passing "--local/-l".
|
||||
N.B. If using the "--" style to pass arguments, flags (e.g. "--local/-l") must
|
||||
be passed *before* the "--". It is possible to pass arguments without the "--"
|
||||
as long as no dashes are present (i.e. "foo" works without "--", "-foo"
|
||||
does not).`,
|
||||
Example: ` # pass <cmd> args/flags without "--"
|
||||
does not).`),
|
||||
Example: i18n.G(` # pass <cmd> args/flags without "--"
|
||||
abra app cmd 1312.net app my_cmd_arg foo --user bar
|
||||
|
||||
# pass <cmd> args/flags with "--"
|
||||
abra app cmd 1312.net app my_cmd_args --user bar -- foo -vvv
|
||||
|
||||
# drop the [service] arg if using "--local/-l"
|
||||
abra app cmd 1312.net my_cmd --local`,
|
||||
abra app cmd 1312.net my_cmd --local`),
|
||||
Args: func(cmd *cobra.Command, args []string) error {
|
||||
if local {
|
||||
if !(len(args) >= 2) {
|
||||
return errors.New("requires at least 2 arguments with --local/-l")
|
||||
return errors.New(i18n.G("requires at least 2 arguments with --local/-l"))
|
||||
}
|
||||
|
||||
if slices.Contains(os.Args, "--") {
|
||||
if cmd.ArgsLenAtDash() > 2 {
|
||||
return errors.New("accepts at most 2 args with --local/-l")
|
||||
return errors.New(i18n.G("accepts at most 2 args with --local/-l"))
|
||||
}
|
||||
}
|
||||
|
||||
@ -63,7 +64,7 @@ does not).`,
|
||||
}
|
||||
|
||||
if !(len(args) >= 3) {
|
||||
return errors.New("requires at least 3 arguments")
|
||||
return errors.New(i18n.G("requires at least 3 arguments"))
|
||||
}
|
||||
|
||||
return nil
|
||||
@ -97,14 +98,14 @@ does not).`,
|
||||
}
|
||||
|
||||
if local && remoteUser != "" {
|
||||
log.Fatal("cannot use --local & --user together")
|
||||
log.Fatal(i18n.G("cannot use --local & --user together"))
|
||||
}
|
||||
|
||||
hasCmdArgs, parsedCmdArgs := parseCmdArgs(args, local)
|
||||
|
||||
if _, err := os.Stat(app.Recipe.AbraShPath); err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
log.Fatalf("%s does not exist for %s?", app.Recipe.AbraShPath, app.Name)
|
||||
log.Fatal(i18n.G("%s does not exist for %s?", app.Recipe.AbraShPath, app.Name))
|
||||
}
|
||||
log.Fatal(err)
|
||||
}
|
||||
@ -115,7 +116,7 @@ does not).`,
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
log.Debugf("--local detected, running %s on local work station", cmdName)
|
||||
log.Debug(i18n.G("--local detected, running %s on local work station", cmdName))
|
||||
|
||||
var exportEnv string
|
||||
for k, v := range app.Env {
|
||||
@ -124,16 +125,16 @@ does not).`,
|
||||
|
||||
var sourceAndExec string
|
||||
if hasCmdArgs {
|
||||
log.Debugf("parsed following command arguments: %s", parsedCmdArgs)
|
||||
log.Debug(i18n.G("parsed following command arguments: %s", parsedCmdArgs))
|
||||
sourceAndExec = fmt.Sprintf("TARGET=local; APP_NAME=%s; STACK_NAME=%s; %s . %s; %s %s", app.Name, app.StackName(), exportEnv, app.Recipe.AbraShPath, cmdName, parsedCmdArgs)
|
||||
} else {
|
||||
log.Debug("did not detect any command arguments")
|
||||
log.Debug(i18n.G("did not detect any command arguments"))
|
||||
sourceAndExec = fmt.Sprintf("TARGET=local; APP_NAME=%s; STACK_NAME=%s; %s . %s; %s", app.Name, app.StackName(), exportEnv, app.Recipe.AbraShPath, cmdName)
|
||||
}
|
||||
|
||||
shell := "/bin/bash"
|
||||
if _, err := os.Stat(shell); errors.Is(err, os.ErrNotExist) {
|
||||
log.Debugf("%s does not exist locally, use /bin/sh as fallback", shell)
|
||||
log.Debug(i18n.G("%s does not exist locally, use /bin/sh as fallback", shell))
|
||||
shell = "/bin/sh"
|
||||
}
|
||||
cmd := exec.Command(shell, "-c", sourceAndExec)
|
||||
@ -164,15 +165,15 @@ does not).`,
|
||||
}
|
||||
|
||||
if !matchingServiceName {
|
||||
log.Fatalf("no service %s for %s?", targetServiceName, app.Name)
|
||||
log.Fatal(i18n.G("no service %s for %s?", targetServiceName, app.Name))
|
||||
}
|
||||
|
||||
log.Debugf("running command %s within the context of %s_%s", cmdName, app.StackName(), targetServiceName)
|
||||
log.Debug(i18n.G("running command %s within the context of %s_%s", cmdName, app.StackName(), targetServiceName))
|
||||
|
||||
if hasCmdArgs {
|
||||
log.Debugf("parsed following command arguments: %s", parsedCmdArgs)
|
||||
log.Debug(i18n.G("parsed following command arguments: %s", parsedCmdArgs))
|
||||
} else {
|
||||
log.Debug("did not detect any command arguments")
|
||||
log.Debug(i18n.G("did not detect any command arguments"))
|
||||
}
|
||||
|
||||
cl, err := client.New(app.Server)
|
||||
@ -192,9 +193,9 @@ does not).`,
|
||||
}
|
||||
|
||||
var AppCmdListCommand = &cobra.Command{
|
||||
Use: "list <domain> [flags]",
|
||||
Aliases: []string{"ls"},
|
||||
Short: "List all available commands",
|
||||
Use: i18n.G("list <domain> [flags]"),
|
||||
Aliases: []string{i18n.G("ls")},
|
||||
Short: i18n.G("List all available commands"),
|
||||
Args: cobra.MinimumNArgs(1),
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
app := internal.ValidateApp(args)
|
||||
@ -244,33 +245,33 @@ var (
|
||||
func init() {
|
||||
AppCmdCommand.Flags().BoolVarP(
|
||||
&local,
|
||||
"local",
|
||||
"l",
|
||||
i18n.G("local"),
|
||||
i18n.G("l"),
|
||||
false,
|
||||
"run command locally",
|
||||
i18n.G("run command locally"),
|
||||
)
|
||||
|
||||
AppCmdCommand.Flags().StringVarP(
|
||||
&remoteUser,
|
||||
"user",
|
||||
"u",
|
||||
i18n.G("user"),
|
||||
i18n.G("u"),
|
||||
"",
|
||||
"request remote user",
|
||||
i18n.G("request remote user"),
|
||||
)
|
||||
|
||||
AppCmdCommand.Flags().BoolVarP(
|
||||
&disableTTY,
|
||||
"tty",
|
||||
"T",
|
||||
i18n.G("tty"),
|
||||
i18n.G("T"),
|
||||
false,
|
||||
"disable remote TTY",
|
||||
i18n.G("disable remote TTY"),
|
||||
)
|
||||
|
||||
AppCmdCommand.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