shellcli

package
v0.0.0-...-4d5f9bd Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

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 {
	Commands        map[string]*Command[T]
	Splitter        splitter.Splitter
	ArgSplitter     splitter.Splitter
	CaseInsensitive bool
	Prompter        func(*ShellCli[T]) string
	Data            *T
}

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]) 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]) Prompt

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

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

Jump to

Keyboard shortcuts

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