plugin

package
v0.3.11 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package plugin assists at building the plugin's main

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CmdName

func CmdName() string

CmdName returns the arg[0] of this executable

func MustRoot added in v0.3.10

func MustRoot(cfg *Config) *cobra.Command

MustRoot generates a root cobra.Command for the plugin's main, and panics if there is an error

func NewRoot

func NewRoot(cfg *Config) (*cobra.Command, error)

NewRoot generates a root cobra.Command for the plugin's main

Types

type Config

type Config struct {
	Name    string // Name is the intended executable's name
	Short   string // Short is the short description shown on help
	Version string // Version indicates the version of the generator

	// Run represents the main loop of the generator, returning the
	// exit code
	Run func(io.ReadCloser, io.WriteCloser) int

	// RunE is an alternative to Run that returns an error directly
	RunE func(io.ReadCloser, io.WriteCloser) error
}

Config specifies how the plugin operates

func (*Config) SetDefaults

func (cfg *Config) SetDefaults()

SetDefaults attempts to fill possible gaps in the config

type ExitCoder added in v0.3.11

type ExitCoder interface {
	Error() string
	ExitCode() int
}

An ExitCoder is a fatal error that tells us how to [os.Exit()]

type ExitError

type ExitError struct {
	Err  error
	Code int
}

ExitError is an error that is expected to be handled directly via os.Exit(e.Code)

func WithExitCode added in v0.3.11

func WithExitCode(err error, code int) *ExitError

WithExitCode wraps a fatal error in ExitError so callers know how to os.Exit

func (*ExitError) Error

func (e *ExitError) Error() string

func (*ExitError) ExitCode added in v0.3.11

func (e *ExitError) ExitCode() int

ExitCode returns the value to be used on os.Exit calls

func (*ExitError) Unwrap added in v0.3.11

func (e *ExitError) Unwrap() error

Jump to

Keyboard shortcuts

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