command

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CommandPartsNumber = 2
	LineUp             = "\x1b[1A"
	LineClear          = "\x1b[2K"
	HideCursor         = "\x1b[?25l"
	ShowCursor         = "\x1b[?25h"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CmdEdit

type CmdEdit struct{}

func NewCmdEdit

func NewCmdEdit() *CmdEdit

func (*CmdEdit) Execute

func (c *CmdEdit) Execute(exCtx ExecutionContext) (Executer, error)

Execute executes the CmdEdit and returns an Executer and an error. It prompts the user to edit a command and returns the corresponding Command object.

type Config

type Config struct {
	Version string              `yaml:"version"`
	Macro   map[string][]string `yaml:"macro"`
	Domains []string            `yaml:"domains"`
}

type Edit

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

func NewEdit

func NewEdit(content string) *Edit

func (*Edit) Execute

func (c *Edit) Execute(exCtx ExecutionContext) (Executer, error)

Execute executes the edit command and returns a Send command id editing was successful or an error in other case.

type Editor

type Editor interface {
	Edit(keyStream <-chan keyboard.KeyEvent, initBuffer string) (string, error)
	Close() error
}

type ErrConnectionClosed

type ErrConnectionClosed struct{}

func (ErrConnectionClosed) Error

func (e ErrConnectionClosed) Error() string

type ErrDuplicateMacro

type ErrDuplicateMacro struct {
	MacroName string
}

func (ErrDuplicateMacro) Error

func (e ErrDuplicateMacro) Error() string

type ErrEmptyCommand

type ErrEmptyCommand struct{}

func (ErrEmptyCommand) Error

func (e ErrEmptyCommand) Error() string

type ErrEmptyMacro

type ErrEmptyMacro struct {
	MacroName string
}

func (ErrEmptyMacro) Error

func (e ErrEmptyMacro) Error() string

type ErrEmptyRequest

type ErrEmptyRequest struct{}

func (ErrEmptyRequest) Error

func (e ErrEmptyRequest) Error() string

type ErrInvalidRepeatCommand added in v0.4.0

type ErrInvalidRepeatCommand struct{}

func (ErrInvalidRepeatCommand) Error added in v0.4.0

func (e ErrInvalidRepeatCommand) Error() string

type ErrInvalidTimeout

type ErrInvalidTimeout struct {
	Timeout string
}

func (ErrInvalidTimeout) Error

func (e ErrInvalidTimeout) Error() string

type ErrTimeout

type ErrTimeout struct{}

func (ErrTimeout) Error

func (e ErrTimeout) Error() string

type ErrUnknownCommand

type ErrUnknownCommand struct {
	Command string
}

func (ErrUnknownCommand) Error

func (e ErrUnknownCommand) Error() string

type ErrUnsupportedMessageType

type ErrUnsupportedMessageType struct {
	MsgType string
}

func (ErrUnsupportedMessageType) Error

type ErrUnsupportedVersion

type ErrUnsupportedVersion struct {
	Version string
}

func (ErrUnsupportedVersion) Error

func (e ErrUnsupportedVersion) Error() string

type Executer

type Executer interface {
	Execute(ExecutionContext) (Executer, error)
}

func Factory

func Factory(raw string, macro *Macro) (Executer, error)

Factory returns an Executer and an error. It takes a string and a Macro pointer as input. The string is split into parts and the first part is used to determine which command to execute. Depending on the command, different arguments are passed to the corresponding constructor. If the command is not recognized, an error is returned.

type ExecutionContext

type ExecutionContext interface {
	Input() <-chan keyboard.KeyEvent
	OutputFile() io.Writer
	Output() io.Writer
	Formater() formater.Formater
	Connection() ws.ConnectionHandler
	RequestEditor() Editor
	CmdEditor() Editor
	Macro() *Macro
}

type Exit

type Exit struct{}

func NewExit

func NewExit() *Exit

func (*Exit) Execute

func (c *Exit) Execute(_ ExecutionContext) (Executer, error)

Execute method implements the Execute method of the Executer interface. It returns an error indicating that the program was interrupted.

type InputFileCommand added in v0.4.0

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

func NewInputFileCommand added in v0.4.0

func NewInputFileCommand(filePath string) *InputFileCommand

func (*InputFileCommand) Execute added in v0.4.0

func (c *InputFileCommand) Execute(exCtx ExecutionContext) (Executer, error)

Execute executes the InputFileCommand and returns an Executer and an error. It reads the file and executes the commands in the file.

type Macro

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

func LoadFromFile

func LoadFromFile(path string) (*Macro, error)

LoadFromFile loads a macro configuration from a file at the given path. It returns a Macro instance and an error if the file cannot be read or parsed.

func LoadMacroForDomain

func LoadMacroForDomain(macroDir, domain string) (*Macro, error)

LoadMacroForDomain loads a macro for a given domain from a directory. It takes the directory path and the domain name as input parameters. It returns a pointer to a Macro struct and an error if any.

func NewMacro

func NewMacro(domains []string) *Macro

NewMacro creates a new Macro instance with the specified domains. The domains parameter is a slice of strings representing the allowed domains for the macro. Returns a pointer to the newly created Macro instance.

func (*Macro) AddCommands

func (m *Macro) AddCommands(name string, rawCommands []string) error

AddCommands adds a new macro with the given name and commands to the Macro instance. If a macro with the same name already exists, it returns an error. If the rawCommands slice is empty, it returns an error. If the rawCommands slice has only one command, it adds the command directly to the macro. Otherwise, it creates a new Sequence with the commands and adds it to the macro.

func (*Macro) Get

func (m *Macro) Get(name, argString string) (Executer, error)

Get returns the Executer associated with the given name, or an error if the name is not found.

func (*Macro) GetNames

func (m *Macro) GetNames() []string

type MacroTemplates added in v0.4.0

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

func NewMacroTemplates added in v0.4.0

func NewMacroTemplates(templates []string) (*MacroTemplates, error)

func (*MacroTemplates) GetExecuter added in v0.4.0

func (t *MacroTemplates) GetExecuter(args []string) (Executer, error)

type PrintMsg

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

func NewPrintMsg

func NewPrintMsg(msg ws.Message) *PrintMsg

func (*PrintMsg) Execute

func (c *PrintMsg) Execute(exCtx ExecutionContext) (Executer, error)

Execute executes the PrintMsg command and returns nil and error. It formats the message and prints it to the output file. If an output file is provided, it writes the formatted message to the file.

type RepeatCommand added in v0.4.0

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

func NewRepeatCommand added in v0.4.0

func NewRepeatCommand(times int, subCommand Executer) *RepeatCommand

func (*RepeatCommand) Execute added in v0.4.0

func (c *RepeatCommand) Execute(exCtx ExecutionContext) (Executer, error)

Execute executes the RepeatCommand and returns an Executer and an error. It executes the sub-command the specified number of times.

type Send

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

func NewSend

func NewSend(request string) *Send

func (*Send) Execute

func (c *Send) Execute(exCtx ExecutionContext) (Executer, error)

Execute sends the request using the WebSocket connection and returns a PrintMsg to print the response message. It implements the Execute method of the Executer interface.

type Sequence

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

func NewSequence

func NewSequence(subCommands []Executer) *Sequence

func (*Sequence) Execute

func (c *Sequence) Execute(exCtx ExecutionContext) (Executer, error)

Execute executes the command sequence by iterating over all sub-commands and executing them recursively. It takes an ExecutionContext as input and returns an Executer and an error.

type SleepCommand added in v0.4.0

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

func NewSleepCommand added in v0.4.0

func NewSleepCommand(duration time.Duration) *SleepCommand

func (*SleepCommand) Execute added in v0.4.0

func (c *SleepCommand) Execute(_ ExecutionContext) (Executer, error)

Execute executes the SleepCommand and returns an Executer and an error. It sleeps for the specified duration.

type WaitForResp

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

func NewWaitForResp

func NewWaitForResp(timeout time.Duration) *WaitForResp

func (*WaitForResp) Execute

func (c *WaitForResp) Execute(exCtx ExecutionContext) (Executer, error)

Execute executes the WaitForResp command and waits for a response from the WebSocket connection. If a timeout is set, it will return an error if no response is received within the specified time. If a response is received, it will return a new PrintMsg command with the received message. If the WebSocket connection is closed, it will return an error.

Jump to

Keyboard shortcuts

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