app

package
v0.0.0-...-f808c62 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2018 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Overview

The app package provides a simple App struct to describe a command-line application, and a Usage interface, which describers the global and command-specific usage of the App.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetVersionMetadata

func SetVersionMetadata(metadata VersionMetadata)

Sets the version metadata for the build. One pattern for setting version metadata is to provide a generated file in the project's main package that constructs a VersionMetadata object and invokes this method.

Note that go build tags (see https://golang.org/pkg/go/build/) may be used to provide compile-time alternates for release builds.

Types

type App

type App struct {
	Name          string // the binary name of the application
	Description   string // a short description of what the application does
	VersionString string // the current version of the application
	HasSubCmds    bool   // whether or not the app has sub commands
}

A simple representation of a command-line application

func (App) RedirectedUsage

func (a App) RedirectedUsage(writer io.Writer) Usage

RedirectedUsage produces a Usage for this App, which prints tab-formatted output to the given Writer at a width of 80 columns.

func (App) Usage

func (a App) Usage() Usage

Usage produces the default implementation of Usage for this App, which prints tab-formatted output to STDOUT.

func (App) Version

func (a App) Version() Version

type MockUsage

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

MockUsage is a mock of Usage interface

func NewMockUsage

func NewMockUsage(ctrl *gomock.Controller) *MockUsage

NewMockUsage creates a new mock instance

func (*MockUsage) Command

func (m *MockUsage) Command(cmd *command.Cmd, globalFlagsFromEnv, cmdFlagsFromEnv flag.FromEnv)

Command mocks base method

func (*MockUsage) EXPECT

func (m *MockUsage) EXPECT() *MockUsageMockRecorder

EXPECT returns an object that allows the caller to indicate expected use

func (*MockUsage) Global

func (m *MockUsage) Global(cmds []*command.Cmd, flagsFromEnv flag.FromEnv)

Global mocks base method

type MockUsageMockRecorder

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

MockUsageMockRecorder is the mock recorder for MockUsage

func (*MockUsageMockRecorder) Command

func (mr *MockUsageMockRecorder) Command(cmd, globalFlagsFromEnv, cmdFlagsFromEnv interface{}) *gomock.Call

Command indicates an expected call of Command

func (*MockUsageMockRecorder) Global

func (mr *MockUsageMockRecorder) Global(cmds, flagsFromEnv interface{}) *gomock.Call

Global indicates an expected call of Global

type MockVersion

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

MockVersion is a mock of Version interface

func NewMockVersion

func NewMockVersion(ctrl *gomock.Controller) *MockVersion

NewMockVersion creates a new mock instance

func (*MockVersion) Describe

func (m *MockVersion) Describe() string

Describe mocks base method

func (*MockVersion) EXPECT

func (m *MockVersion) EXPECT() *MockVersionMockRecorder

EXPECT returns an object that allows the caller to indicate expected use

func (*MockVersion) Metadata

func (m *MockVersion) Metadata() VersionMetadata

Metadata mocks base method

func (*MockVersion) Version

func (m *MockVersion) Version() string

Version mocks base method

type MockVersionMockRecorder

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

MockVersionMockRecorder is the mock recorder for MockVersion

func (*MockVersionMockRecorder) Describe

func (mr *MockVersionMockRecorder) Describe() *gomock.Call

Describe indicates an expected call of Describe

func (*MockVersionMockRecorder) Metadata

func (mr *MockVersionMockRecorder) Metadata() *gomock.Call

Metadata indicates an expected call of Metadata

func (*MockVersionMockRecorder) Version

func (mr *MockVersionMockRecorder) Version() *gomock.Call

Version indicates an expected call of Version

type Usage

type Usage interface {
	// Global outputs the global usage for an App, based on the provided
	// command.Cmds and flag.FlagSet
	Global(cmds []*command.Cmd, flagsFromEnv tbnflag.FromEnv)
	// Command outputs the usage for the given command.Cmd, including global and
	// command flags.
	Command(cmd *command.Cmd, globalFlagsFromEnv tbnflag.FromEnv, cmdFlagsFromEnv tbnflag.FromEnv)
}

Usage provides methods to output global and command-specific usage of an App. No specific output format or destination is specified by the interface.

type Version

type Version interface {
	Describe() string

	Version() string
	Metadata() VersionMetadata
}

type VersionMetadata

type VersionMetadata struct {
	BranchName string
	Revision   string
	BuiltAt    time.Time
	BuiltBy    string
}

func GetVersionMetadata

func GetVersionMetadata() VersionMetadata

Gets the version metadata for the build. May be useful for forensics.

Jump to

Keyboard shortcuts

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