fixed version blocking (#251)

This commit is contained in:
RoyUP9
2021-08-30 15:11:14 +03:00
committed by GitHub
parent 80237c8090
commit e25e7925b6
3 changed files with 14 additions and 6 deletions

View File

@@ -10,6 +10,7 @@ import (
"github.com/up9inc/mizu/cli/mizu/fsUtils" "github.com/up9inc/mizu/cli/mizu/fsUtils"
"github.com/up9inc/mizu/cli/mizu/version" "github.com/up9inc/mizu/cli/mizu/version"
"github.com/up9inc/mizu/cli/uiUtils" "github.com/up9inc/mizu/cli/uiUtils"
"time"
) )
var rootCmd = &cobra.Command{ var rootCmd = &cobra.Command{
@@ -34,9 +35,12 @@ func init() {
} }
func printNewVersionIfNeeded(versionChan chan string) { func printNewVersionIfNeeded(versionChan chan string) {
versionMsg := <-versionChan select {
if versionMsg != "" { case versionMsg := <-versionChan:
logger.Log.Infof(uiUtils.Yellow, versionMsg) if versionMsg != "" {
logger.Log.Infof(uiUtils.Yellow, versionMsg)
}
case <-time.After(2 * time.Second):
} }
} }

View File

@@ -40,8 +40,7 @@ func InitConfig(cmd *cobra.Command) error {
configFilePathFlag := cmd.Flags().Lookup(ConfigFilePathCommandName) configFilePathFlag := cmd.Flags().Lookup(ConfigFilePathCommandName)
configFilePath := configFilePathFlag.Value.String() configFilePath := configFilePathFlag.Value.String()
if err := mergeConfigFile(configFilePath); err != nil { if err := mergeConfigFile(configFilePath); err != nil {
_, isPathError := err.(*os.PathError) if configFilePathFlag.Changed || !os.IsNotExist(err) {
if configFilePathFlag.Changed || !isPathError {
return fmt.Errorf("invalid config, %w\n"+ return fmt.Errorf("invalid config, %w\n"+
"you can regenerate the file by removing it (%v) and using `mizu config -r`", err, configFilePath) "you can regenerate the file by removing it (%v) and using `mizu config -r`", err, configFilePath)
} }

View File

@@ -37,6 +37,7 @@ func CheckNewerVersion(versionChan chan string) {
latestRelease, _, err := client.Repositories.GetLatestRelease(context.Background(), "up9inc", "mizu") latestRelease, _, err := client.Repositories.GetLatestRelease(context.Background(), "up9inc", "mizu")
if err != nil { if err != nil {
logger.Log.Debugf("[ERROR] Failed to get latest release") logger.Log.Debugf("[ERROR] Failed to get latest release")
versionChan <- ""
return return
} }
@@ -49,12 +50,14 @@ func CheckNewerVersion(versionChan chan string) {
} }
if versionFileUrl == "" { if versionFileUrl == "" {
logger.Log.Debugf("[ERROR] Version file not found in the latest release") logger.Log.Debugf("[ERROR] Version file not found in the latest release")
versionChan <- ""
return return
} }
res, err := http.Get(versionFileUrl) res, err := http.Get(versionFileUrl)
if err != nil { if err != nil {
logger.Log.Debugf("[ERROR] Failed to get the version file %v", err) logger.Log.Debugf("[ERROR] Failed to get the version file %v", err)
versionChan <- ""
return return
} }
@@ -62,6 +65,7 @@ func CheckNewerVersion(versionChan chan string) {
res.Body.Close() res.Body.Close()
if err != nil { if err != nil {
logger.Log.Debugf("[ERROR] Failed to read the version file -> %v", err) logger.Log.Debugf("[ERROR] Failed to read the version file -> %v", err)
versionChan <- ""
return return
} }
gitHubVersion := string(data) gitHubVersion := string(data)
@@ -73,6 +77,7 @@ func CheckNewerVersion(versionChan chan string) {
if gitHubVersionSemVer.GreaterThan(currentSemVer) { if gitHubVersionSemVer.GreaterThan(currentSemVer) {
versionChan <- fmt.Sprintf("Update available! %v -> %v (%v)", mizu.SemVer, gitHubVersion, *latestRelease.HTMLURL) versionChan <- fmt.Sprintf("Update available! %v -> %v (%v)", mizu.SemVer, gitHubVersion, *latestRelease.HTMLURL)
} else {
versionChan <- ""
} }
versionChan <- ""
} }