version

package
v0.7.0-alpha.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 3, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package version provides the version command.

Index

Constants

This section is empty.

Variables

View Source
var (
	Commit  = "none"
	Date    = "unknown"
	BuiltBy = "unknown"
)

These variables are set via -ldflags during the build process. Example: -ldflags "-X github.com/contextvibes/cli/cmd/version.Commit=$(git rev-parse HEAD)".

View Source
var VersionCmd = &cobra.Command{
	Use:   "version",
	Short: "Print the version and build information",
	RunE: func(cmd *cobra.Command, _ []string) error {

		if shortFlag {
			fmt.Fprintln(cmd.OutOrStdout(), globals.AppVersion)

			return nil
		}

		info := Info{
			Version:   globals.AppVersion,
			Commit:    Commit,
			Date:      Date,
			GoVersion: runtime.Version(),
			OS:        runtime.GOOS,
			Arch:      runtime.GOARCH,
			BuiltBy:   BuiltBy,
		}

		if jsonFlag {
			enc := json.NewEncoder(cmd.OutOrStdout())
			enc.SetIndent("", "  ")

			return enc.Encode(info)
		}

		if yamlFlag {
			enc := yaml.NewEncoder(cmd.OutOrStdout())

			return enc.Encode(info)
		}

		fmt.Fprintf(cmd.OutOrStdout(), "ContextVibes CLI\n")
		fmt.Fprintf(cmd.OutOrStdout(), "  Version:    %s\n", info.Version)
		fmt.Fprintf(cmd.OutOrStdout(), "  Commit:     %s\n", info.Commit)
		fmt.Fprintf(cmd.OutOrStdout(), "  Built:      %s\n", info.Date)
		fmt.Fprintf(cmd.OutOrStdout(), "  Go Version: %s\n", info.GoVersion)
		fmt.Fprintf(cmd.OutOrStdout(), "  OS/Arch:    %s/%s\n", info.OS, info.Arch)

		return nil
	},
}

VersionCmd represents the version command.

Functions

This section is empty.

Types

type Info

type Info struct {
	Version   string `json:"version"   yaml:"version"`
	Commit    string `json:"commit"    yaml:"commit"`
	Date      string `json:"date"      yaml:"date"`
	GoVersion string `json:"goVersion" yaml:"goVersion"`
	OS        string `json:"os"        yaml:"os"`
	Arch      string `json:"arch"      yaml:"arch"`
	BuiltBy   string `json:"builtBy"   yaml:"builtBy"`
}

Info represents the build information.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL