command

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2023 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrParse = fmt.Errorf("couldn't parse commands")

Functions

func New

func New(cfg *Config) *runner

New returns a new command runner.

func NewNopCommand

func NewNopCommand(name string) *nopCommand

NewNopCommand creates a new nop command with the given name

Types

type BashCommand

type BashCommand struct {
	// contains filtered or unexported fields
}

BashCommand executes a bash command

func (*BashCommand) Name

func (c *BashCommand) Name() string

func (*BashCommand) Run

func (c *BashCommand) Run(ctx context.Context, args []any) any

type BingCommand

type BingCommand struct {
	// contains filtered or unexported fields
}

BingCommand asks bing chat the given question

func (*BingCommand) Name

func (c *BingCommand) Name() string

func (*BingCommand) Run

func (c *BingCommand) Run(ctx context.Context, args []any) any

type Command

type Command interface {
	Name() string
	Run(ctx context.Context, args []any) any
}

type CommandRequest

type CommandRequest struct {
	// Command name
	Name string `json:"name"`
	// Command arguments
	Args []any `json:"args"`
}

CommandRequest represents a single command request

func Parse

func Parse(text string) ([]CommandRequest, error)

Parse tries to parse a JSON array of commands from the given text.

type Config added in v1.1.0

type Config struct {
	Exit      func()
	Output    string
	Bing      io.ReadWriter
	GoogleKey string
	GoogleCX  string
}

Config represents the configuration for a command runner.

type DeleteFileCommand

type DeleteFileCommand struct {
	// contains filtered or unexported fields
}

DeleteFileCommand deletes a file from the output directory

func (*DeleteFileCommand) Name

func (c *DeleteFileCommand) Name() string

func (*DeleteFileCommand) Run

func (c *DeleteFileCommand) Run(ctx context.Context, args []any) any

type ExitCommand

type ExitCommand struct {
	// contains filtered or unexported fields
}

func (*ExitCommand) Name

func (c *ExitCommand) Name() string

func (*ExitCommand) Run

func (c *ExitCommand) Run(ctx context.Context, args []any) any

type GoogleCommand

type GoogleCommand struct {
	// contains filtered or unexported fields
}

func (*GoogleCommand) Name

func (c *GoogleCommand) Name() string

func (*GoogleCommand) Run

func (c *GoogleCommand) Run(ctx context.Context, args []any) any

type ListFilesCommand

type ListFilesCommand struct {
	// contains filtered or unexported fields
}

ListFilesCommand lists files in the output directory

func (*ListFilesCommand) Name

func (c *ListFilesCommand) Name() string

func (*ListFilesCommand) Run

func (c *ListFilesCommand) Run(ctx context.Context, args []any) any

type ReadFileCommand

type ReadFileCommand struct {
	// contains filtered or unexported fields
}

ReadFileCommand reads a file from the output directory

func (*ReadFileCommand) Name

func (c *ReadFileCommand) Name() string

func (*ReadFileCommand) Run

func (c *ReadFileCommand) Run(ctx context.Context, args []any) any

type WebCommand

type WebCommand struct{}

func (*WebCommand) Name

func (c *WebCommand) Name() string

func (*WebCommand) Run

func (c *WebCommand) Run(ctx context.Context, args []any) any

type WriteFileCommand

type WriteFileCommand struct {
	// contains filtered or unexported fields
}

WriteFileCommand writes a file to the output directory

func (*WriteFileCommand) Name

func (c *WriteFileCommand) Name() string

func (*WriteFileCommand) Run

func (c *WriteFileCommand) Run(ctx context.Context, args []any) any

Jump to

Keyboard shortcuts

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