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
binary: psu
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:
- CGO_ENABLED=0
goos:

View File

@ -5,9 +5,10 @@ import (
"os"
"strings"
"github.com/greenled/portainer-stack-utils/version"
"github.com/sirupsen/logrus"
"github.com/greenled/portainer-stack-utils/common"
"github.com/mitchellh/go-homedir"
"github.com/spf13/cobra"
"github.com/spf13/viper"
@ -35,7 +36,7 @@ func init() {
cobra.OnInitialize(initConfig, initLogger)
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().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"
"strings"
"github.com/greenled/portainer-stack-utils/version"
"github.com/greenled/portainer-stack-utils/client"
"github.com/sirupsen/logrus"
@ -92,7 +94,7 @@ func GetDefaultClientConfig() (config client.Config, err error) {
User: viper.GetString("user"),
Password: viper.GetString("password"),
Token: viper.GetString("auth-token"),
UserAgent: BuildUseAgentString(),
UserAgent: version.BuildUseAgentString(),
DoNotUseToken: false,
}

View File

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