mirror of
https://github.com/anchore/syft
synced 2024-11-13 23:57:07 +00:00
341288ba29
* refactor signing steps in release/snapshot workflows Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * show signing logs on snapshot or release failure Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * update install.sh + tests to account for new goreleaser changes Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * update cli tests to account for new goreleaser build names Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * fix acceptance test to use new snapshot bin path Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * add notarization Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * address review comments Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
60 lines
1.5 KiB
Go
60 lines
1.5 KiB
Go
package cmd
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/anchore/syft/internal"
|
|
|
|
"github.com/anchore/syft/internal/version"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
var outputFormat string
|
|
|
|
var versionCmd = &cobra.Command{
|
|
Use: "version",
|
|
Short: "show the version",
|
|
Run: printVersion,
|
|
}
|
|
|
|
func init() {
|
|
versionCmd.Flags().StringVarP(&outputFormat, "output", "o", "text", "format to show version information (available=[text, json])")
|
|
rootCmd.AddCommand(versionCmd)
|
|
}
|
|
|
|
func printVersion(_ *cobra.Command, _ []string) {
|
|
versionInfo := version.FromBuild()
|
|
|
|
switch outputFormat {
|
|
case "text":
|
|
fmt.Println("Application: ", internal.ApplicationName)
|
|
fmt.Println("Version: ", versionInfo.Version)
|
|
fmt.Println("BuildDate: ", versionInfo.BuildDate)
|
|
fmt.Println("GitCommit: ", versionInfo.GitCommit)
|
|
fmt.Println("GitDescription: ", versionInfo.GitDescription)
|
|
fmt.Println("Platform: ", versionInfo.Platform)
|
|
fmt.Println("GoVersion: ", versionInfo.GoVersion)
|
|
fmt.Println("Compiler: ", versionInfo.Compiler)
|
|
|
|
case "json":
|
|
enc := json.NewEncoder(os.Stdout)
|
|
enc.SetEscapeHTML(false)
|
|
enc.SetIndent("", " ")
|
|
err := enc.Encode(&struct {
|
|
version.Version
|
|
Application string `json:"application"`
|
|
}{
|
|
Version: versionInfo,
|
|
Application: internal.ApplicationName,
|
|
})
|
|
if err != nil {
|
|
fmt.Printf("failed to show version information: %+v\n", err)
|
|
os.Exit(1)
|
|
}
|
|
default:
|
|
fmt.Printf("unsupported output format: %s\n", outputFormat)
|
|
os.Exit(1)
|
|
}
|
|
}
|