Documentation
¶
Overview ¶
Package tool implements the reflow command.
Index ¶
- type Cmd
- func (c *Cmd) Errorf(format string, v ...interface{})
- func (c Cmd) Errorln(v ...interface{})
- func (c *Cmd) Exit(code int)
- func (c *Cmd) Fatal(v ...interface{})
- func (c *Cmd) Fatalf(format string, v ...interface{})
- func (c *Cmd) Flags() *flag.FlagSet
- func (c *Cmd) Main()
- func (c *Cmd) Parse(fs *flag.FlagSet, args []string, help, usage string)
- func (c *Cmd) Printf(format string, v ...interface{})
- func (c *Cmd) Println(v ...interface{})
- type Func
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) 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 ¶
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 ¶
Fatalf formats a message in the manner of fmt.Printf, prints it to stderr, and then exits the tool.
func (*Cmd) Flags ¶
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 ¶
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.