Mover version-related code to the version package

This commit is contained in:
Juan Carlos Mejías Rodríguez 2019-08-13 23:33:49 -04:00
parent 50d246ecf7
commit 0cdaf49425
4 changed files with 8 additions and 5 deletions

View File

@ -8,7 +8,7 @@ builds:
- main: main.go - main: main.go
binary: psu binary: psu
ldflags: ldflags:
- -X github.com/greenled/portainer-stack-utils/common.version={{ .Version }} -X github.com/greenled/portainer-stack-utils/common.commitHash={{ .ShortCommit }} -X github.com/greenled/portainer-stack-utils/common.buildDate={{ .Date }} - -X github.com/greenled/portainer-stack-utils/version.version={{ .Version }} -X github.com/greenled/portainer-stack-utils/version.commitHash={{ .ShortCommit }} -X github.com/greenled/portainer-stack-utils/version.buildDate={{ .Date }}
env: env:
- CGO_ENABLED=0 - CGO_ENABLED=0
goos: goos:

View File

@ -5,9 +5,10 @@ import (
"os" "os"
"strings" "strings"
"github.com/greenled/portainer-stack-utils/version"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"github.com/greenled/portainer-stack-utils/common"
"github.com/mitchellh/go-homedir" "github.com/mitchellh/go-homedir"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/spf13/viper" "github.com/spf13/viper"
@ -35,7 +36,7 @@ func init() {
cobra.OnInitialize(initConfig, initLogger) cobra.OnInitialize(initConfig, initLogger)
rootCmd.SetVersionTemplate("{{ version }}\n") rootCmd.SetVersionTemplate("{{ version }}\n")
cobra.AddTemplateFunc("version", common.BuildVersionString) cobra.AddTemplateFunc("version", version.BuildVersionString)
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "Config file. (default \"$HOME/.psu.yaml)\"") rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "Config file. (default \"$HOME/.psu.yaml)\"")
rootCmd.PersistentFlags().StringP("log-level", "v", "info", "Log level. One of trace, debug, info, warning, error, fatal or panic.") rootCmd.PersistentFlags().StringP("log-level", "v", "info", "Log level. One of trace, debug, info, warning, error, fatal or panic.")

View File

@ -8,6 +8,8 @@ import (
"net/url" "net/url"
"strings" "strings"
"github.com/greenled/portainer-stack-utils/version"
"github.com/greenled/portainer-stack-utils/client" "github.com/greenled/portainer-stack-utils/client"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
@ -92,7 +94,7 @@ func GetDefaultClientConfig() (config client.Config, err error) {
User: viper.GetString("user"), User: viper.GetString("user"),
Password: viper.GetString("password"), Password: viper.GetString("password"),
Token: viper.GetString("auth-token"), Token: viper.GetString("auth-token"),
UserAgent: BuildUseAgentString(), UserAgent: version.BuildUseAgentString(),
DoNotUseToken: false, DoNotUseToken: false,
} }

View File

@ -1,4 +1,4 @@
package common package version
import ( import (
"fmt" "fmt"