program

package module
v0.0.0-...-904b3e9 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2024 License: ISC Imports: 12 Imported by: 11

README

go-program

Introduction

The go-program library contains utilities to parse command line arguments. Compared to the standard flag package, go-program uses the same conventions than most UNIX programs.

Usage

Refer to the Go package documentation for information about the API.

See the cmd/examples directory for examples.

Licensing

Go-program is open source software distributed under the ISC license.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Argument

type Argument struct {
	Name        string
	Description string
	Optional    bool
	Trailing    bool

	Set            bool
	Value          string
	TrailingValues []string
}

type BuildId

type BuildId struct {
	Major int
	Minor int
	Patch int

	NbCommits *int
	Revision  *string
}

func (BuildId) EqualTo

func (id1 BuildId) EqualTo(id2 BuildId) bool

func (BuildId) IsStable

func (id BuildId) IsStable() bool

func (BuildId) LowerThanOrEqualTo

func (id1 BuildId) LowerThanOrEqualTo(id2 BuildId) bool

func (*BuildId) Parse

func (id *BuildId) Parse(s string) error

func (BuildId) String

func (id BuildId) String() string

type Command

type Command struct {
	Name        string
	Description string
	Main        Main
	// contains filtered or unexported fields
}

func (*Command) AddArgument

func (c *Command) AddArgument(name, description string)

func (*Command) AddFlag

func (c *Command) AddFlag(shortName, longName, description string)

func (*Command) AddOption

func (c *Command) AddOption(shortName, longName, valueName, defaultValue, description string)

func (*Command) AddOptionalArgument

func (c *Command) AddOptionalArgument(name, description string)

func (*Command) AddTrailingArgument

func (c *Command) AddTrailingArgument(name, description string)

type Main

type Main func(*Program)

type Option

type Option struct {
	ShortName    string
	LongName     string
	ValueName    string
	DefaultValue string
	Description  string

	Set   bool
	Value string
}

type Program

type Program struct {
	Name        string
	Description string
	Main        Main

	Quiet      bool
	DebugLevel int
	// contains filtered or unexported fields
}

func NewProgram

func NewProgram(name, description string) *Program

func (*Program) AddArgument

func (p *Program) AddArgument(name, description string)

func (*Program) AddCommand

func (p *Program) AddCommand(name, description string, main Main) *Command

func (*Program) AddFlag

func (p *Program) AddFlag(shortName, longName, description string)

func (*Program) AddOption

func (p *Program) AddOption(shortName, longName, valueName, defaultValue, description string)

func (*Program) AddOptionalArgument

func (p *Program) AddOptionalArgument(name, description string)

func (*Program) AddTrailingArgument

func (p *Program) AddTrailingArgument(name, description string)

func (*Program) ArgumentValue

func (p *Program) ArgumentValue(name string) string

func (*Program) CommandName

func (p *Program) CommandName() string

func (*Program) Debug

func (p *Program) Debug(level int, format string, args ...interface{})

func (*Program) Error

func (p *Program) Error(format string, args ...interface{})

func (*Program) Fatal

func (p *Program) Fatal(format string, args ...interface{})

func (*Program) Info

func (p *Program) Info(format string, args ...interface{})

func (*Program) IsOptionSet

func (p *Program) IsOptionSet(name string) bool

func (*Program) OptionValue

func (p *Program) OptionValue(name string) string

func (*Program) OptionalArgumentValue

func (p *Program) OptionalArgumentValue(name string) *string

func (*Program) ParseCommandLine

func (p *Program) ParseCommandLine()

func (*Program) PrintUsage

func (p *Program) PrintUsage(command *Command)

func (*Program) Run

func (p *Program) Run()

func (*Program) SetMain

func (p *Program) SetMain(main Main)

func (*Program) TrailingArgumentValues

func (p *Program) TrailingArgumentValues(name string) []string

type Table

type Table struct {
	Columns []TableColumn
	Rows    [][]interface{}
}

func NewTable

func NewTable() *Table

func (*Table) AddColumn

func (t *Table) AddColumn(c TableColumn)

func (*Table) AddRow

func (t *Table) AddRow(row ...interface{})

func (*Table) Print

func (t *Table) Print()

func (*Table) Render

func (t *Table) Render() [][]string

func (*Table) RenderValue

func (t *Table) RenderValue(value interface{}) (s string)

type TableCellAlignment

type TableCellAlignment string
const (
	TableCellAlignmentLeft  TableCellAlignment = "left"
	TableCellAlignmentRight TableCellAlignment = "right"
)

type TableColumn

type TableColumn struct {
	Label     string
	Alignment TableCellAlignment
}

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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