From ea54aa75dba4e4674aa5c49102d3f5edf0ff5603 Mon Sep 17 00:00:00 2001 From: LinkinStars Date: Thu, 11 May 2023 11:36:23 +0800 Subject: [PATCH] feat(upgrade): replace i18n bundle using the upgrade command --- cmd/command.go | 1 + internal/cli/install.go | 10 +++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/cmd/command.go b/cmd/command.go index bfcb1414..67f9ce34 100644 --- a/cmd/command.go +++ b/cmd/command.go @@ -101,6 +101,7 @@ To run answer, use: Long: `upgrade Answer version`, Run: func(_ *cobra.Command, _ []string) { cli.FormatAllPath(dataDirPath) + cli.InstallI18nBundle(true) c, err := conf.ReadConfig(cli.GetConfigFilePath()) if err != nil { fmt.Println("read config failed: ", err.Error()) diff --git a/internal/cli/install.go b/internal/cli/install.go index e2d278f1..5fb4fe1f 100644 --- a/internal/cli/install.go +++ b/internal/cli/install.go @@ -40,7 +40,7 @@ func FormatAllPath(dataDirPath string) { func InstallAllInitialEnvironment(dataDirPath string) { FormatAllPath(dataDirPath) installUploadDir() - installI18nBundle() + InstallI18nBundle(false) fmt.Println("install all initial environment done") } @@ -79,7 +79,7 @@ func installUploadDir() { } } -func installI18nBundle() { +func InstallI18nBundle(replace bool) { fmt.Println("[i18n] try to install i18n bundle...") if err := dir.CreateDirIfNotExist(I18nPath); err != nil { fmt.Println(err.Error()) @@ -98,7 +98,11 @@ func installI18nBundle() { if err != nil { continue } - if dir.CheckFileExist(path) { + exist := dir.CheckFileExist(path) + if exist && !replace { + continue + } + if exist { fmt.Printf("[i18n] install %s file exist, try to replace it\n", item.Name()) if err = os.Remove(path); err != nil { fmt.Println(err)