shellcli

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetFunctionName added in v0.9.3

func GetFunctionName(i interface{}) string

func OnInterrupt added in v0.9.3

func OnInterrupt(fn func())

func OnReload added in v0.9.3

func OnReload(fn func())

Types

type Command

type Command[T any] struct {
	Description string
	Args        [][3]string // Map of argument to the description and default value
	Run         func(a *ShellCli[T], args map[string]string) error
}

Command is a command for the shell client

type ShellCli

type ShellCli[T any] struct {
	ProjectName     string
	Commands        map[string]*Command[T]
	Splitter        splitter.Splitter
	ArgSplitter     splitter.Splitter
	CaseInsensitive bool
	Prompter        func(*ShellCli[T]) string
	Data            *T
	// contains filtered or unexported fields
}

ShellCli is a simple shell-like interface with commands

func (*ShellCli[T]) AddCommand

func (a *ShellCli[T]) AddCommand(name string, cmd *Command[T])

AddCommand adds a command to the shell client

It is recommended to use this to add a command over directly modifying the Commands map as this function will be updated to be backwards compatible with future changes

func (*ShellCli[T]) Exec

func (a *ShellCli[T]) Exec(cmd []string) error

Exec executes a command

func (*ShellCli[T]) ExecuteCommands added in v1.5.0

func (a *ShellCli[T]) ExecuteCommands(cmd string) (cancel bool, err error)

ExecuteCommands handles a list of commands in the form 'cmd; cmd etc.'

func (*ShellCli[T]) Help

func (s *ShellCli[T]) Help() *Command[T]

Returns a help command

func (*ShellCli[T]) Init

func (a *ShellCli[T]) Init() error

Init initializes the shell client

func (*ShellCli[T]) Run

func (a *ShellCli[T]) Run()

Run constantly prompts for input and os.Exit()'s on interrupt signal

Only use this for actual shell apps

func (*ShellCli[T]) RunString added in v0.9.3

func (a *ShellCli[T]) RunString(command string) (bool, error)

Jump to

Keyboard shortcuts

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