versioninfo

package module
v2.24.1 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2024 License: MIT Imports: 7 Imported by: 69

README

versioninfo GoDoc Go Report Card

Importable package that parses debug.ReadBuildInfo() for inclusion in your Go application. Requires Go 1.18+.

Examples

package main

import (
    "fmt"

    "github.com/earthboundkid/versioninfo/v2"
)

func main() {
    fmt.Println("Version:", versioninfo.Version)
    fmt.Println("Revision:", versioninfo.Revision)
    fmt.Println("DirtyBuild:", versioninfo.DirtyBuild)
    fmt.Println("LastCommit:", versioninfo.LastCommit)
}

You may use the concatenated information provided by versioninfo.Short():

package main

import (
    "fmt"

    "github.com/earthboundkid/versioninfo/v2"
)

func main() {
    fmt.Println("ShortInfo:", versioninfo.Short())
}

Add the -v and -version flags:

package main

import (
    "flag"
    "fmt"

    "github.com/earthboundkid/versioninfo/v2"
)

func main() {
    versioninfo.AddFlag(nil)
    flag.Parse()
    fmt.Println("done")
}

Documentation

Overview

Package versioninfo uses runtime.ReadBuildInfo() to set global executable revision information if possible.

Index

Constants

This section is empty.

Variables

View Source
var (
	// Version will be the version tag if the binary is built with "go install url/tool@version".
	// If the binary is built some other way, it will be "(devel)".
	Version = "unknown"
	// Revision is taken from the vcs.revision tag in Go 1.18+.
	Revision = "unknown"
	// LastCommit is taken from the vcs.time tag in Go 1.18+.
	LastCommit time.Time
	// DirtyBuild is taken from the vcs.modified tag in Go 1.18+.
	DirtyBuild = true
)

Functions

func AddFlag

func AddFlag(f *flag.FlagSet)

AddFlag adds -v and -version flags to the FlagSet. If triggered, the flags print version information and call os.Exit(0). If FlagSet is nil, it adds the flags to flag.CommandLine.

func Short

func Short() string

Short provides a short string summarizing available version information.

Types

This section is empty.

Jump to

Keyboard shortcuts

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