tool

package
v0.0.0-...-0f4c570 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2018 License: Apache-2.0 Imports: 59 Imported by: 0

Documentation

Overview

Package tool implements the reflow command.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cmd

type Cmd struct {
	Flag struct {
		Cache         bool
		NoCacheExtern bool
		Project       string
	}

	// Config must be specified.
	Config            config.Config
	DefaultConfigFile string
	Version           string
	Variant           string

	// Commands contains the additional set of invocable commands.
	Commands map[string]Func

	// MakeConfig is called to wrap the base configuration.
	// This allows a tool instance to customize on top of the
	// base configuration.
	MakeConfig func(config.Config) config.Config

	// ConfigFile stores the path of the active configuration file.
	// May be overriden by the -config flag.
	ConfigFile string

	// Intro is an additional introduction printed after the standard one.
	Intro string

	// The standard output and error as defined by this command;
	// these are wrapped through a status writer so that output is
	// properly interleaved.
	Stdout, Stderr io.Writer

	Log *log.Logger
	// contains filtered or unexported fields
}

Cmd holds the configuration, flag definitions, and runtime objects required for tool invocations.

func (*Cmd) Errorf

func (c *Cmd) Errorf(format string, v ...interface{})

Errorf formats a message in the manner of fmt.Printf and prints it to stderr.

func (Cmd) Errorln

func (c Cmd) Errorln(v ...interface{})

Errorln formats a message in the manner of fmt.Println and prints it to stderr.

func (*Cmd) Exit

func (c *Cmd) Exit(code int)

Exit causes the command to exit with the provided status code. Exit ensures that command teardown is properly handled.

func (*Cmd) Fatal

func (c *Cmd) Fatal(v ...interface{})

Fatal formats a message in the manner of fmt.Print, prints it to stderr, and then exits the tool.

func (*Cmd) Fatalf

func (c *Cmd) Fatalf(format string, v ...interface{})

Fatalf formats a message in the manner of fmt.Printf, prints it to stderr, and then exits the tool.

func (*Cmd) Flags

func (c *Cmd) Flags() *flag.FlagSet

Flags initializes and returns the FlagSet used by this Cmd instance. The user should parse this flagset before invoking (*Cmd).Main, e.g.:

cmd.Flags().Parse(os.Args[1:])

func (*Cmd) Main

func (c *Cmd) Main()

Main parses command line flags and then invokes the requested command. Main uses Cmd's config (and other initialization), which may be overriden by flag configs. It should be invoked only once, at the beginning of command line execution. The caller is expected to have parsed the flagset for us before calling Main.

Main should only be called once.

func (*Cmd) Parse

func (c *Cmd) Parse(fs *flag.FlagSet, args []string, help, usage string)

Parse parses the provided FlagSet from the provided arguments. It adds a -help flag to the flagset, and prints the help and usage string when the command is called with -help. On usage error, it prints the flag defaults and exits with code 2.

func (*Cmd) Printf

func (c *Cmd) Printf(format string, v ...interface{})

Printf formats a message in the manner of fmt.Printf and prints it to stdout.

func (*Cmd) Println

func (c *Cmd) Println(v ...interface{})

Println formats a message in the manner of fmt.Println and prints it to stdout.

type Func

type Func func(*Cmd, context.Context, ...string)

Func is the type of a command function.

Jump to

Keyboard shortcuts

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