prog

package
v0.0.0-...-4892080 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2024 License: GPL-3.0 Imports: 8 Imported by: 5

Documentation

Overview

Package prog provides infrastructure for implementing programs with subcommands.

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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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.

Types

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.

Jump to

Keyboard shortcuts

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