Back to godoc.org

Package prog

v0.0.0-...-3cf7f3f
Latest Go to latest

The latest major version is .

Published: May 27, 2020 | License: GPL3 | Module: lab.nexedi.com/kirr/go123

Overview

Package prog provides infrastructure for implementing programs with subcommands.

Usage is simple: initialize a MainProg var appropriately and call its .Main().

Index

func Exit

func Exit(code int)

Exit is like os.Exit but makes sure deferred functions are run.

Exit should be called from main goroutine.

func Fatal

func Fatal(v ...interface{})

Fatal is like log.Fatal but makes sure deferred functions are run.

Fatal should be called from main goroutine.

type Command

type Command struct {
	Name    string
	Summary string
	Usage   func(w io.Writer)
	Main    func(argv []string)
}

Command describes one program subcommand.

type CommandRegistry

type CommandRegistry []Command

CommandRegistry is ordered collection of Commands.

func (CommandRegistry) Lookup

func (cmdv CommandRegistry) Lookup(command string) *Command

Lookup returns Command with corresponding name or nil.

type HelpRegistry

type HelpRegistry []HelpTopic

HelpRegistry is ordered collection of HelpTopics.

func (HelpRegistry) Lookup

func (helpv HelpRegistry) Lookup(topic string) *HelpTopic

Lookup returns HelpTopic with corresponding name or nil.

type HelpTopic

type HelpTopic struct {
	Name    string
	Summary string
	Text    string
}

HelpTopic describes one help topic.

type MainProg

type MainProg struct {
	Name       string          // name of the program, e.g. "zodb"
	Summary    string          // 1-line summary of what program does
	Commands   CommandRegistry // provided subcommands
	HelpTopics HelpRegistry    // provided help topics
}

MainProg defines a program to run with subcommands and help topics.

func (*MainProg) Main

func (prog *MainProg) Main()

Main is the main entry point for the program. Call it from main.

Do not call os.Exit or log.Fatal from your program. Instead use Exit and Fatal from prog package so that deferred functions setup by Main could be run.

Package Files

  • prog.go
Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier