WIP: feat: translation support
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
See #483
This commit is contained in:
@ -6,6 +6,7 @@ import (
|
||||
"coopcloud.tech/abra/cli/internal"
|
||||
"coopcloud.tech/abra/pkg/autocomplete"
|
||||
"coopcloud.tech/abra/pkg/formatter"
|
||||
"coopcloud.tech/abra/pkg/i18n"
|
||||
"coopcloud.tech/abra/pkg/log"
|
||||
"coopcloud.tech/abra/pkg/recipe"
|
||||
"github.com/go-git/go-git/v5"
|
||||
@ -14,19 +15,19 @@ import (
|
||||
)
|
||||
|
||||
var RecipeFetchCommand = &cobra.Command{
|
||||
Use: "fetch [recipe | --all] [flags]",
|
||||
Aliases: []string{"f"},
|
||||
Short: "Clone recipe(s) locally",
|
||||
Long: `Using "--force/-f" Git syncs an existing recipe. It does not erase unstaged changes.`,
|
||||
Use: i18n.G("fetch [recipe | --all] [flags]"),
|
||||
Aliases: []string{i18n.G("f")},
|
||||
Short: i18n.G("Clone recipe(s) locally"),
|
||||
Long: i18n.G(`Using "--force/-f" Git syncs an existing recipe. It does not erase unstaged changes.`),
|
||||
Args: cobra.RangeArgs(0, 1),
|
||||
Example: ` # fetch from recipe catalogue
|
||||
Example: i18n.G(` # fetch from recipe catalogue
|
||||
abra recipe fetch gitea
|
||||
|
||||
# fetch from remote recipe
|
||||
abra recipe fetch git.foo.org/recipes/myrecipe
|
||||
|
||||
# fetch with ssh remote for hacking
|
||||
abra recipe fetch gitea --ssh`,
|
||||
abra recipe fetch gitea --ssh`),
|
||||
ValidArgsFunction: func(
|
||||
cmd *cobra.Command,
|
||||
args []string,
|
||||
@ -40,18 +41,18 @@ var RecipeFetchCommand = &cobra.Command{
|
||||
}
|
||||
|
||||
if recipeName == "" && !fetchAllRecipes {
|
||||
log.Fatal("missing [recipe] or --all/-a")
|
||||
log.Fatal(i18n.G("missing [recipe] or --all/-a"))
|
||||
}
|
||||
|
||||
if recipeName != "" && fetchAllRecipes {
|
||||
log.Fatal("cannot use [recipe] and --all/-a together")
|
||||
log.Fatal(i18n.G("cannot use [recipe] and --all/-a together"))
|
||||
}
|
||||
|
||||
if recipeName != "" {
|
||||
r := recipe.Get(recipeName)
|
||||
if _, err := os.Stat(r.Dir); !os.IsNotExist(err) {
|
||||
if !force {
|
||||
log.Warnf("%s is already fetched", r.Name)
|
||||
log.Warn(i18n.G("%s is already fetched", r.Name))
|
||||
return
|
||||
}
|
||||
}
|
||||
@ -60,24 +61,24 @@ var RecipeFetchCommand = &cobra.Command{
|
||||
|
||||
if sshRemote {
|
||||
if r.SSHURL == "" {
|
||||
log.Warnf("unable to discover SSH remote for %s", r.Name)
|
||||
log.Warn(i18n.G("unable to discover SSH remote for %s", r.Name))
|
||||
return
|
||||
}
|
||||
|
||||
repo, err := git.PlainOpen(r.Dir)
|
||||
if err != nil {
|
||||
log.Fatalf("unable to open %s: %s", r.Dir, err)
|
||||
log.Fatal(i18n.G("unable to open %s: %s", r.Dir, err))
|
||||
}
|
||||
|
||||
if err = repo.DeleteRemote("origin"); err != nil {
|
||||
log.Fatalf("unable to remove default remote in %s: %s", r.Dir, err)
|
||||
log.Fatal(i18n.G("unable to remove default remote in %s: %s", r.Dir, err))
|
||||
}
|
||||
|
||||
if _, err := repo.CreateRemote(&gitCfg.RemoteConfig{
|
||||
Name: "origin",
|
||||
URLs: []string{r.SSHURL},
|
||||
}); err != nil {
|
||||
log.Fatalf("unable to set SSH remote in %s: %s", r.Dir, err)
|
||||
log.Fatal(i18n.G("unable to set SSH remote in %s: %s", r.Dir, err))
|
||||
}
|
||||
}
|
||||
|
||||
@ -89,7 +90,7 @@ var RecipeFetchCommand = &cobra.Command{
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
catlBar := formatter.CreateProgressbar(len(catalogue), "fetching latest recipes...")
|
||||
catlBar := formatter.CreateProgressbar(len(catalogue), i18n.G("fetching latest recipes..."))
|
||||
ensureCtx := internal.GetEnsureContext()
|
||||
for recipeName := range catalogue {
|
||||
r := recipe.Get(recipeName)
|
||||
@ -110,25 +111,25 @@ var (
|
||||
func init() {
|
||||
RecipeFetchCommand.Flags().BoolVarP(
|
||||
&fetchAllRecipes,
|
||||
"all",
|
||||
"a",
|
||||
i18n.G("all"),
|
||||
i18n.G("a"),
|
||||
false,
|
||||
"fetch all recipes",
|
||||
i18n.G("fetch all recipes"),
|
||||
)
|
||||
|
||||
RecipeFetchCommand.Flags().BoolVarP(
|
||||
&sshRemote,
|
||||
"ssh",
|
||||
"s",
|
||||
i18n.G("ssh"),
|
||||
i18n.G("s"),
|
||||
false,
|
||||
"automatically set ssh remote",
|
||||
i18n.G("automatically set ssh remote"),
|
||||
)
|
||||
|
||||
RecipeFetchCommand.Flags().BoolVarP(
|
||||
&force,
|
||||
"force",
|
||||
"f",
|
||||
i18n.G("force"),
|
||||
i18n.G("f"),
|
||||
false,
|
||||
"force re-fetch",
|
||||
i18n.G("force re-fetch"),
|
||||
)
|
||||
}
|
||||
|
Reference in New Issue
Block a user