stamp

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2019 License: BSD-3-Clause Imports: 8 Imported by: 1

README

Build Status codecov Maintainability

stamp - Parses out build information to embed into your binary

Normalize how version and build information makes it's way into your binaries. Generates code that can be used to add flags

-v    Print version and exit
-vv
      Print version with details and exit

Quick start

Install

go get github.com/gregoryv/stamp/...

Example main.go

//go:generate stamp -go build_stamp.go -clfile changelog.md
package main

import (
	"github.com/gregoryv/stamp"
	"flag"
)

func init() {
	// Add -v and -vv flags
	stamp.InitFlags()
}

func main() {
	flag.Parse()
	stamp.AsFlagged()
	//...
}

Then generate with

go generate .
go build .

Details

stamp depends on git and that you have a CHANGELOG.md. The changelog is parsed for the latest released version and assumes it follows http://keepachangelog.com/en/1.0.0/ format.

Documentation

Overview

Package stamp parses build information from git repository and changelog.md

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	Show    = false
	Verbose = false
)

Functions

func AsFlagged

func AsFlagged()

AsFlagged shows information according to flags and exits with code 0

func InitFlags

func InitFlags()

Regiters -v and -vv flags

func NewGoTemplate

func NewGoTemplate() *template.Template

NewGoTemplate returns a go source template

func Print

func Print()
Example
s := &Stamp{
	Revision:         "rev",
	ChangelogVersion: "1.0.2",
}
Use(s)
Print()
Output:

1.0.2

func PrintDetails

func PrintDetails()
Example
s := &Stamp{
	Revision:         "6e6046c",
	ChangelogVersion: "1.0.0",
}
Use(s)
PrintDetails()
Output:

1.0.0-6e6046c

func Revision

func Revision(repoRoot string) (string, error)

Revision returns the short revision for HEAD

func Use

func Use(stamp *Stamp)

Use sets the stamp to use when printing details

Types

type Changelog

type Changelog struct {
	// contains filtered or unexported fields
}

func NewChangelog

func NewChangelog(content []byte) *Changelog

func (*Changelog) Version

func (cl *Changelog) Version() (version string, err error)

type Stamp

type Stamp struct {
	Package          string
	Revision         string
	ChangelogVersion string
}

Stamp collects identifying information about a software library

func InUse added in v0.2.0

func InUse() *Stamp

func NewStamp

func NewStamp() *Stamp

func (*Stamp) ParseChangelog

func (s *Stamp) ParseChangelog(file string) (err error)

ParseChangelog sets ChangelogVersion of this stamp from the given file

type Versioner

type Versioner interface {
	Version() (string, error)
}

Directories

Path Synopsis
cmd
stamp
Command stamp generates go source code with build information.
Command stamp generates go source code with build information.

Jump to

Keyboard shortcuts

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