shell

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2024 License: MIT Imports: 17 Imported by: 1

Documentation

Index

Constants

View Source
const (
	GroupID string = "core"
)

Variables

View Source
var (
	ErrOpenHistoryFile = errors.New("failed to open history file")
	ErrNegativeIndex   = errors.New("cannot use a negative index when requesting historic commands")
)

Functions

func EmbeddedHistory

func EmbeddedHistory(file string, maxLines int, enableLocal ...bool) (readline.History, error)

NewSourceFromFile returns a new history source writing to and reading from a file.

func ExitCtrlD

func ExitCtrlD(c *console.Console)

exitCtrlD is a custom interrupt handler to use when the shell readline receives an io.EOF error, which is returned with CtrlD.

func GetFlagKey

func GetFlagKey(parent, child string) string

func SetupPrompt

func SetupPrompt(m *console.Menu)

setupPrompt is a function which sets up the prompts for the main menu.

func SwitchMenu

func SwitchMenu(c *console.Console)

Types

type Flag

type Flag struct {
	Name    string   // flag name
	Short   string   // flag shorthand
	Type    FlagType // flag type
	Default string   // default value
	Usage   string   // flag help info
}

func (*Flag) GetDefault

func (f *Flag) GetDefault() string

func (*Flag) GetName

func (f *Flag) GetName() string

func (*Flag) GetShort

func (f *Flag) GetShort() string

func (*Flag) GetType

func (f *Flag) GetType() FlagType

func (*Flag) GetUsage

func (f *Flag) GetUsage() string

type FlagType

type FlagType string
const (
	OptionTypeString FlagType = "string"
	OptionTypeBool   FlagType = "bool"
	OptionTypeInt    FlagType = "int"
	OptionTypeFloat  FlagType = "float"
)

type IShell

type IShell struct {
	Console   *console.Console
	SetPrompt func(*console.Menu)
	History   readline.History
	// contains filtered or unexported fields
}

func NewIShell

func NewIShell() (s *IShell)

func (*IShell) AddChild

func (s *IShell) AddChild(parent string, command *ShellCmd)

func (*IShell) AddCmd

func (s *IShell) AddCmd(command *ShellCmd)

func (*IShell) SetHistoryFilePath

func (s *IShell) SetHistoryFilePath(fPath string, maxLine int, enableLocal ...bool)
func (s *IShell) SetPrintLogo(f func(_ *console.Console))

func (*IShell) SetupPrompt

func (s *IShell) SetupPrompt(setp func(*console.Menu))

func (*IShell) Start

func (s *IShell) Start() error

type IShellFlag

type IShellFlag interface {
	GetName() string
	GetShort() string
	GetType() FlagType
	GetDefault() string
	GetUsage() string
}

Flags

type Item

type Item struct {
	Index    int
	DateTime time.Time
	Block    string
}

type ShellCmd

type ShellCmd struct {
	Name        string  // cmd name
	Parent      string  // parent cmd name
	HelpStr     string  // Short for cobra cmd
	LongHelpStr string  // Long for cobra cmd
	Options     []*Flag // flags for cobra
	Run         func(cmd *cobra.Command, args []string)
	Children    []*ShellCmd
}

func NewShellCmd

func NewShellCmd() (sc *ShellCmd)

func (*ShellCmd) AddChild

func (s *ShellCmd) AddChild(child *ShellCmd)

Jump to

Keyboard shortcuts

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