cli

package
v0.0.0-...-51d629d Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2016 License: BSD-3-Clause, BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Overview

This set of routines encapsulates the cli structure, which holds the help text and definitions for a gus cli.

See License for copyright information. Portions of this code are (c) 2012 by the Go Authors. This code has been been adapted for use in GUS and is not the sole work of Charles Gentry.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Box

func Box(w io.Writer, info string)

func Help

func Help(usageTemplate, cmd string, args []string, commands []*Command)

help implements the 'help' cli.

func ParseBool

func ParseBool(txt string) (rtn bool, err error)

func PrintStructValue

func PrintStructValue(w io.Writer, substruct interface{})

func PromptForStructFields

func PromptForStructFields(substruct interface{}, helpTemplate string)

func PromptInteger

func PromptInteger(w io.Writer, r io.Reader, prompt string) (val int, err error)

Simple prompt for interger. Caller can pass buffers or os.Stdin/os.Stdout

func PromptIntegerDefault

func PromptIntegerDefault(w io.Writer, r io.Reader, prompt string, defaultValue int) int

Prompt for a integer value but accept a default value if they don't enter anything.

func PromptString

func PromptString(w io.Writer, r io.Reader, prompt string) (string, error)

func PromptStringDefault

func PromptStringDefault(w io.Writer, r io.Reader, prompt, defaultValue string) string

func PromptYesNo

func PromptYesNo(w io.Writer, r io.Reader, prompt string) (bool, error)

Simple prompt for yes or no values. Caller can pass buffers or os.Stdin/os.Stdout

func PromptYesNoDefault

func PromptYesNoDefault(w io.Writer, r io.Reader, prompt string, defaultValue bool) bool

Prompt for a yes/no value but accept a default value if they don't enter anything.

func RenderTemplate

func RenderTemplate(w io.Writer, text string, data interface{})

RenderTemplate executes the given template text on data, writing the result to w.

func Usage

func Usage(usageTemplate string, commands []*Command)

Types

type Command

type Command struct {
	Name string

	// Run runs the cli.
	// The args are the arguments after the cli name.
	Run func(cmd *Command, args []string)

	// UsageLine is the one-line usage message.
	UsageLine string

	// Short is the short description shown in the 'go help' output.
	Short string

	// Long is the long message shown in the 'go help <this-cli>' output.
	Long string

	// Flag is a set of flags specific to this cli.
	Flag flag.FlagSet

	// CustomFlags indicates that the cli will do its own
	// flag parsing.
	CustomFlags bool
}

A cli is any subcommand, such as createstore (from go source code)

func (*Command) Id

func (t *Command) Id() string

func (*Command) LongHelp

func (t *Command) LongHelp() string

func (*Command) Runnable

func (c *Command) Runnable() bool

Runnable reports whether the cli can be run; otherwise it is a documentation pseudo-cli such as importpath.

func (*Command) ShortHelp

func (t *Command) ShortHelp() string

func (*Command) Usage

func (c *Command) Usage()

type Helper

type Helper interface {
	Id() string
	ShortHelp() string
	LongHelp() string
}

type StructNameList

type StructNameList struct {
	Name string
	Help string
}

Jump to

Keyboard shortcuts

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