Skip to content

Commit

Permalink
Add version command and enhance versioning information in CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
dz0ny committed Dec 10, 2024
1 parent 29b2a27 commit 4e2b2ed
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 4 deletions.
4 changes: 3 additions & 1 deletion .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ builds:
goarch:
- amd64
- arm64
gcflags:
- all=-trimpath=${GOPATH}
ldflags:
- -s -w -X paretosecurity.com/auditor/shared.Version={{.Version}}
- -s -w -X shared.Version={{.Version}} -X shared.Commit={{.Commit}} -X shared.Date={{.Date}}
binary: paretosecurity

archives:
Expand Down
2 changes: 2 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ var rootCmd = &cobra.Command{
Long: `Pareto Security CLI is a tool for running and reporting audits
to paretosecurity.com.`,
PersistentPreRun: func(cmd *cobra.Command, args []string) {

if verbose {
log.SetLevel(log.DebugLevel)
}
Expand All @@ -21,6 +22,7 @@ to paretosecurity.com.`,

func init() {
rootCmd.PersistentFlags().BoolVar(&verbose, "verbose", false, "output verbose logs")

}

func Execute() {
Expand Down
22 changes: 22 additions & 0 deletions cmd/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package cmd

import (
"os"

"github.com/caarlos0/log"
"github.com/spf13/cobra"
"paretosecurity.com/auditor/shared"
)

var versionCmd = &cobra.Command{
Use: "version",
Short: "Print the version information",
Run: func(cmd *cobra.Command, args []string) {
log.Infof("%s@%s %s", shared.Version, shared.Commit, shared.Date)
os.Exit(0)
},
}

func init() {
rootCmd.AddCommand(versionCmd)
}
2 changes: 1 addition & 1 deletion shared/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func createSafeHTTPClient() *http.Client {
// Wrap the transport to insert the User-Agent header
client.Transport = &userAgentTransport{
Transport: customTransport,
agent: fmt.Sprintf("Pareto Security/%s (Linux; build:%s)", Version, Hash),
agent: fmt.Sprintf("Pareto Security/%s (Linux; build:%s)", Version, Commit),
}

return client
Expand Down
7 changes: 5 additions & 2 deletions shared/version.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
package shared

const Version = "0.1.0"
const Hash = "dev"
var (
Version = "dev"
Commit = "none"
Date = "unknown"
)

0 comments on commit 4e2b2ed

Please sign in to comment.