mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2025-09-08 14:15:30 +08:00
BUG: User-Agent should include DNSControl version (#3653)
Co-authored-by: Tom Limoncelli <tlimoncelli@stackoverflow.com>
This commit is contained in:
parent
b66251bfda
commit
cd8892f9bb
8 changed files with 30 additions and 32 deletions
|
@ -22,7 +22,7 @@ builds:
|
||||||
goarch: "386"
|
goarch: "386"
|
||||||
ldflags:
|
ldflags:
|
||||||
- -linkmode=internal -s -w
|
- -linkmode=internal -s -w
|
||||||
- -X main.version={{ .Version }}
|
- -X github.com/StackExchange/dnscontrol/v4/pkg/version.version={{ .Version }}
|
||||||
before:
|
before:
|
||||||
hooks:
|
hooks:
|
||||||
- go fmt ./...
|
- go fmt ./...
|
||||||
|
|
|
@ -15,7 +15,7 @@ var goos = flag.String("os", "", "OS to build (linux, windows, or darwin) Defaul
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
flags := fmt.Sprintf(`-s -w -X "main.version=%s"`, getVersion())
|
flags := fmt.Sprintf(`-s -w -X "github.com/StackExchange/dnscontrol/v4/pkg/version.version=%s"`, getVersion())
|
||||||
pkg := "github.com/StackExchange/dnscontrol/v4"
|
pkg := "github.com/StackExchange/dnscontrol/v4"
|
||||||
|
|
||||||
build := func(out, goos string) {
|
build := func(out, goos string) {
|
||||||
|
|
|
@ -11,6 +11,7 @@ import (
|
||||||
"github.com/StackExchange/dnscontrol/v4/pkg/diff2"
|
"github.com/StackExchange/dnscontrol/v4/pkg/diff2"
|
||||||
"github.com/StackExchange/dnscontrol/v4/pkg/js"
|
"github.com/StackExchange/dnscontrol/v4/pkg/js"
|
||||||
"github.com/StackExchange/dnscontrol/v4/pkg/printer"
|
"github.com/StackExchange/dnscontrol/v4/pkg/printer"
|
||||||
|
"github.com/StackExchange/dnscontrol/v4/pkg/version"
|
||||||
"github.com/fatih/color"
|
"github.com/fatih/color"
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
)
|
)
|
||||||
|
@ -34,16 +35,15 @@ var _ = cmd(catDebug, &cli.Command{
|
||||||
Name: "version",
|
Name: "version",
|
||||||
Usage: "Print version information",
|
Usage: "Print version information",
|
||||||
Action: func(c *cli.Context) error {
|
Action: func(c *cli.Context) error {
|
||||||
_, err := fmt.Println(version)
|
_, err := fmt.Println(version.Version())
|
||||||
return err
|
return err
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
// Run will execute the CLI
|
// Run will execute the CLI
|
||||||
func Run(v string) int {
|
func Run(v string) int {
|
||||||
version = v
|
|
||||||
app := cli.NewApp()
|
app := cli.NewApp()
|
||||||
app.Version = version
|
app.Version = v
|
||||||
app.Name = "dnscontrol"
|
app.Name = "dnscontrol"
|
||||||
app.HideVersion = true
|
app.HideVersion = true
|
||||||
app.Usage = "DNSControl is a compiler and DSL for managing dns zones"
|
app.Usage = "DNSControl is a compiler and DSL for managing dns zones"
|
||||||
|
|
|
@ -4,14 +4,10 @@ import (
|
||||||
_ "embed" // Required by go:embed
|
_ "embed" // Required by go:embed
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
"github.com/StackExchange/dnscontrol/v4/pkg/version"
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
// GoReleaser: version
|
|
||||||
var (
|
|
||||||
version = "dev"
|
|
||||||
)
|
|
||||||
|
|
||||||
var _ = cmd(catUtils, func() *cli.Command {
|
var _ = cmd(catUtils, func() *cli.Command {
|
||||||
var args TypesArgs
|
var args TypesArgs
|
||||||
return &cli.Command{
|
return &cli.Command{
|
||||||
|
@ -58,7 +54,7 @@ func WriteTypes(args TypesArgs) error {
|
||||||
if _, err := file.WriteString("// To update it, run `dnscontrol write-types`.\n\n"); err != nil {
|
if _, err := file.WriteString("// To update it, run `dnscontrol write-types`.\n\n"); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if _, err := file.WriteString("// " + version + "\n"); err != nil {
|
if _, err := file.WriteString("// " + version.Version() + "\n"); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if _, err := file.WriteString(dtsContent); err != nil {
|
if _, err := file.WriteString(dtsContent); err != nil {
|
||||||
|
|
11
main.go
11
main.go
|
@ -6,20 +6,13 @@ import (
|
||||||
"runtime/debug"
|
"runtime/debug"
|
||||||
|
|
||||||
"github.com/StackExchange/dnscontrol/v4/commands"
|
"github.com/StackExchange/dnscontrol/v4/commands"
|
||||||
|
"github.com/StackExchange/dnscontrol/v4/pkg/version"
|
||||||
_ "github.com/StackExchange/dnscontrol/v4/providers/_all"
|
_ "github.com/StackExchange/dnscontrol/v4/providers/_all"
|
||||||
"github.com/fatih/color"
|
"github.com/fatih/color"
|
||||||
)
|
)
|
||||||
|
|
||||||
//go:generate go run build/generate/generate.go build/generate/featureMatrix.go build/generate/functionTypes.go build/generate/dtsFile.go build/generate/ownersFile.go
|
//go:generate go run build/generate/generate.go build/generate/featureMatrix.go build/generate/functionTypes.go build/generate/dtsFile.go build/generate/ownersFile.go
|
||||||
|
|
||||||
// Version management. Goals:
|
|
||||||
// 1. Someone who just does "go get" has at least some information.
|
|
||||||
// 2. If built with build/build.go, more specific build information gets put in.
|
|
||||||
// GoReleaser: version
|
|
||||||
var (
|
|
||||||
version = "dev"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
if os.Getenv("CI") == "true" {
|
if os.Getenv("CI") == "true" {
|
||||||
color.NoColor = false
|
color.NoColor = false
|
||||||
|
@ -27,5 +20,5 @@ func main() {
|
||||||
if info, ok := debug.ReadBuildInfo(); !ok && info == nil {
|
if info, ok := debug.ReadBuildInfo(); !ok && info == nil {
|
||||||
fmt.Fprint(os.Stderr, "Warning: dnscontrol was built without Go modules. See https://docs.dnscontrol.org/getting-started/getting-started#source for more information on how to build dnscontrol correctly.\n\n")
|
fmt.Fprint(os.Stderr, "Warning: dnscontrol was built without Go modules. See https://docs.dnscontrol.org/getting-started/getting-started#source for more information on how to build dnscontrol correctly.\n\n")
|
||||||
}
|
}
|
||||||
os.Exit(commands.Run("DNSControl version " + version))
|
os.Exit(commands.Run("DNSControl version " + version.Version()))
|
||||||
}
|
}
|
||||||
|
|
17
pkg/version/version.go
Normal file
17
pkg/version/version.go
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
package version
|
||||||
|
|
||||||
|
import "runtime/debug"
|
||||||
|
|
||||||
|
// Set by GoReleaser
|
||||||
|
var version string
|
||||||
|
|
||||||
|
func Version() string {
|
||||||
|
if version != "" {
|
||||||
|
return version
|
||||||
|
}
|
||||||
|
bi, ok := debug.ReadBuildInfo()
|
||||||
|
if !ok {
|
||||||
|
return "dev"
|
||||||
|
}
|
||||||
|
return bi.Main.Version
|
||||||
|
}
|
|
@ -6,15 +6,11 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
|
"github.com/StackExchange/dnscontrol/v4/pkg/version"
|
||||||
"github.com/StackExchange/dnscontrol/v4/providers"
|
"github.com/StackExchange/dnscontrol/v4/providers"
|
||||||
cnrcl "github.com/centralnicgroup-opensource/rtldev-middleware-go-sdk/v5/apiclient"
|
cnrcl "github.com/centralnicgroup-opensource/rtldev-middleware-go-sdk/v5/apiclient"
|
||||||
)
|
)
|
||||||
|
|
||||||
// GoReleaser: version
|
|
||||||
var (
|
|
||||||
version = "dev"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Client describes a connection to the CNR API.
|
// Client describes a connection to the CNR API.
|
||||||
type Client struct {
|
type Client struct {
|
||||||
conf map[string]string
|
conf map[string]string
|
||||||
|
@ -61,7 +57,7 @@ func newProvider(conf map[string]string) (*Client, error) {
|
||||||
conf: conf,
|
conf: conf,
|
||||||
client: cnrcl.NewAPIClient(),
|
client: cnrcl.NewAPIClient(),
|
||||||
}
|
}
|
||||||
api.client.SetUserAgent("DNSControl", version)
|
api.client.SetUserAgent("DNSControl", version.Version())
|
||||||
api.APILogin, api.APIPassword, api.APIEntity = conf["apilogin"], conf["apipassword"], conf["apientity"]
|
api.APILogin, api.APIPassword, api.APIEntity = conf["apilogin"], conf["apipassword"], conf["apientity"]
|
||||||
if conf["debugmode"] == "2" {
|
if conf["debugmode"] == "2" {
|
||||||
api.client.EnableDebugMode()
|
api.client.EnableDebugMode()
|
||||||
|
|
|
@ -5,15 +5,11 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
|
"github.com/StackExchange/dnscontrol/v4/pkg/version"
|
||||||
"github.com/StackExchange/dnscontrol/v4/providers"
|
"github.com/StackExchange/dnscontrol/v4/providers"
|
||||||
hxcl "github.com/centralnicgroup-opensource/rtldev-middleware-go-sdk/v4/apiclient"
|
hxcl "github.com/centralnicgroup-opensource/rtldev-middleware-go-sdk/v4/apiclient"
|
||||||
)
|
)
|
||||||
|
|
||||||
// GoReleaser: version
|
|
||||||
var (
|
|
||||||
version = "dev"
|
|
||||||
)
|
|
||||||
|
|
||||||
// HXClient describes a connection to the hexonet API.
|
// HXClient describes a connection to the hexonet API.
|
||||||
type HXClient struct {
|
type HXClient struct {
|
||||||
APILogin string
|
APILogin string
|
||||||
|
@ -42,7 +38,7 @@ func newProvider(conf map[string]string) (*HXClient, error) {
|
||||||
api := &HXClient{
|
api := &HXClient{
|
||||||
client: hxcl.NewAPIClient(),
|
client: hxcl.NewAPIClient(),
|
||||||
}
|
}
|
||||||
api.client.SetUserAgent("DNSControl", version)
|
api.client.SetUserAgent("DNSControl", version.Version())
|
||||||
api.APILogin, api.APIPassword, api.APIEntity = conf["apilogin"], conf["apipassword"], conf["apientity"]
|
api.APILogin, api.APIPassword, api.APIEntity = conf["apilogin"], conf["apipassword"], conf["apientity"]
|
||||||
if conf["debugmode"] == "1" {
|
if conf["debugmode"] == "1" {
|
||||||
api.client.EnableDebugMode()
|
api.client.EnableDebugMode()
|
||||||
|
|
Loading…
Add table
Reference in a new issue