common

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2022 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

Variables

View Source
var EmptyCompResult = &CompResult{
	Flag: cobra.ShellCompDirectiveNoFileComp,
}

Functions

func Build

func Build[Context any](cmd *cobra.Command, app App[Context])

func Comp

func Comp(actions ...CompAction) func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective)

Types

type App

type App[Context any] interface {
	BuildContext(args Args) (*Context, error)
	Ops() []Operation[Context]

	Close(ctx *Context) error
}

type Args

type Args []string

func (Args) Get

func (a Args) Get(idx int) string

func (Args) GetDefault

func (a Args) GetDefault(idx int, def string) string

type CompAction

type CompAction func(args Args) (*CompResult, error)

type CompResult

type CompResult struct {
	Items []string
	Flag  cobra.ShellCompDirective
}

type NoneContext

type NoneContext struct{}

func (NoneContext) BuildContext

func (NoneContext) BuildContext(Args) (*struct{}, error)

func (NoneContext) Close

func (NoneContext) Close(_ *struct{}) error

type Operation

type Operation[Context any] interface {
	Use() string
	Desc() string
	Action() string

	Prepare(cmd *cobra.Command)
	Run(ctx *Context, args Args) error
}

Jump to

Keyboard shortcuts

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