Skip to content

Commit

Permalink
fix bug when running version cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
Oleg Sucharevich authored Feb 13, 2019
1 parent 455b343 commit 6e37e11
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 29 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "venona",
"version": "0.15.0",
"version": "0.15.1",
"description": "Codefresh agent to run on Codefresh's runtime environment and execute pipeline",
"main": "index.js",
"scripts": {
Expand Down
61 changes: 33 additions & 28 deletions venonactl/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,36 +62,11 @@ var rootCmd = &cobra.Command{

PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
fullPath := cmd.CommandPath()
isVersionTarget := strings.Index(fullPath, "version") != -1
if verbose == true {
logrus.SetLevel(logrus.DebugLevel)
}

if configPath == "" {
configPath = fmt.Sprintf("%s/.cfconfig", os.Getenv("HOME"))
}

if cfAPIHost == "" && cfAPIToken == "" {
context, err := sdkUtils.ReadAuthContext(configPath, cfContext)
if err != nil {
return err
}
cfAPIHost = context.URL
cfAPIToken = context.Token

logrus.WithFields(logrus.Fields{
"Context-Name": context.Name,
"Codefresh-Host": cfAPIHost,
}).Debug("Using codefresh context")
} else {
logrus.Debug("Using creentials from environment variables")
}
client := codefresh.New(&codefresh.ClientOptions{
Auth: codefresh.AuthOptions{
Token: cfAPIToken,
},
Host: cfAPIHost,
})

s := store.GetStore()
s.Version = &store.Version{
Current: &store.CurrentVersion{
Expand All @@ -104,6 +79,7 @@ var rootCmd = &cobra.Command{
s.Image = &store.Image{
Name: "codefresh/venona",
}

if skipVerionCheck || localDevFlow == "true" {
latestVersion := &store.LatestVersion{
Version: store.DefaultVersion,
Expand All @@ -124,14 +100,44 @@ var rootCmd = &cobra.Command{
res, _ := store.IsRunningLatestVersion()
// the local version and the latest version not match
// make sure the command is no venonactl version
if !res && strings.Index(fullPath, "version") == -1 {
if !res && !isVersionTarget {
logrus.WithFields(logrus.Fields{
"Local-Version": s.Version.Current.Version,
"Latest-Version": s.Version.Latest.Version,
}).Info("New version is avaliable, please update")
}
}

if isVersionTarget {
return nil
}

if configPath == "" {
configPath = fmt.Sprintf("%s/.cfconfig", os.Getenv("HOME"))
}

if cfAPIHost == "" && cfAPIToken == "" {
context, err := sdkUtils.ReadAuthContext(configPath, cfContext)
if err != nil {
return err
}
cfAPIHost = context.URL
cfAPIToken = context.Token

logrus.WithFields(logrus.Fields{
"Context-Name": context.Name,
"Codefresh-Host": cfAPIHost,
}).Debug("Using codefresh context")
} else {
logrus.Debug("Using creentials from environment variables")
}
client := codefresh.New(&codefresh.ClientOptions{
Auth: codefresh.AuthOptions{
Token: cfAPIToken,
},
Host: cfAPIHost,
})

if kubeConfigPath == "" {
currentUser, _ := user.Current()
if currentUser != nil {
Expand All @@ -153,7 +159,6 @@ var rootCmd = &cobra.Command{
Client: client,
}
s.Mode = store.ModeInCluster

s.ServerCert = &certs.ServerCert{}

return nil
Expand Down

0 comments on commit 6e37e11

Please sign in to comment.