xmain

package
v0.0.12 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2022 License: MPL-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package xmain provides a standard stub for the main of a command handling logging, flags, signals and shutdown.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DiscardSlog

func DiscardSlog(ctx context.Context) context.Context

TODO: remove after removing slog

func Main

func Main(run RunFunc)

Types

type ExitError

type ExitError struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
}

func ExitErrorf

func ExitErrorf(code int, msg string, v ...interface{}) ExitError

func (ExitError) Error

func (ee ExitError) Error() string

type RunFunc

type RunFunc func(context.Context, *State) error

type State

type State struct {
	Name string

	Stdin  io.Reader
	Stdout io.WriteCloser
	Stderr io.WriteCloser

	Log     *cmdlog.Logger
	Env     *xos.Env
	Args    []string
	FlagSet *pflag.FlagSet
}

func (*State) FlagHelp

func (ms *State) FlagHelp() string

func (*State) Main

func (ms *State) Main(ctx context.Context, sigs <-chan os.Signal, run func(context.Context, *State) error) error

func (*State) ReadPath

func (ms *State) ReadPath(fp string) ([]byte, error)

func (*State) WritePath

func (ms *State) WritePath(fp string, p []byte) error

type UsageError

type UsageError struct {
	Message string `json:"message"`
}

func UsageErrorf

func UsageErrorf(msg string, v ...interface{}) UsageError

func (UsageError) Error

func (ue UsageError) Error() string

Jump to

Keyboard shortcuts

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