command

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PartsNumber = 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

NewCmdEdit initializes and returns a new instance of CmdEdit. It does not take any parameters. It returns a pointer to CmdEdit, which can execute an edit command.

func (*CmdEdit) Execute

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

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

type Edit

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

func NewEdit

func NewEdit(content string) *Edit

NewEdit creates a new Edit command with the specified content. It takes a single parameter, content, of type string, which represents the initial content for editing. It returns a pointer to an Edit struct initialized with the provided content.

func (*Edit) Execute

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

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

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

type ErrInvalidRepeatCommand struct{}

func (ErrInvalidRepeatCommand) Error

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 Exit

type Exit struct{}

func NewExit

func NewExit() *Exit

NewExit creates and returns a new instance of the Exit command. It takes no parameters and returns a pointer to an Exit struct.

func (*Exit) Execute

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

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

type Factory

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

func NewFactory

func NewFactory(macro MacroRepo) *Factory

func (*Factory) Create

func (f *Factory) Create(raw string) (core.Executer, error)

type InputFileCommand

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

func NewInputFileCommand

func NewInputFileCommand(filePath string) *InputFileCommand

NewInputFileCommand creates a new InputFileCommand instance. It takes filePath of type string, which specifies the path to the input file. It returns a pointer to an InputFileCommand initialized with the given file path.

func (*InputFileCommand) Execute

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

type MacroRepo added in v0.7.0

type MacroRepo interface {
	Get(name, argString string) (core.Executer, error)
}

type MockMacroRepo added in v0.7.0

type MockMacroRepo struct {
	mock.Mock
}

MockMacroRepo is an autogenerated mock type for the MacroRepo type

func NewMockMacroRepo added in v0.7.0

func NewMockMacroRepo(t interface {
	mock.TestingT
	Cleanup(func())
}) *MockMacroRepo

NewMockMacroRepo creates a new instance of MockMacroRepo. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. The first argument is typically a *testing.T value.

func (*MockMacroRepo) EXPECT added in v0.7.0

func (_m *MockMacroRepo) EXPECT() *MockMacroRepo_Expecter

func (*MockMacroRepo) Get added in v0.7.0

func (_m *MockMacroRepo) Get(name string, argString string) (core.Executer, error)

Get provides a mock function with given fields: name, argString

type MockMacroRepo_Expecter added in v0.7.0

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

func (*MockMacroRepo_Expecter) Get added in v0.7.0

func (_e *MockMacroRepo_Expecter) Get(name interface{}, argString interface{}) *MockMacroRepo_Get_Call

Get is a helper method to define mock.On call

  • name string
  • argString string

type MockMacroRepo_Get_Call added in v0.7.0

type MockMacroRepo_Get_Call struct {
	*mock.Call
}

MockMacroRepo_Get_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Get'

func (*MockMacroRepo_Get_Call) Return added in v0.7.0

func (*MockMacroRepo_Get_Call) Run added in v0.7.0

func (_c *MockMacroRepo_Get_Call) Run(run func(name string, argString string)) *MockMacroRepo_Get_Call

func (*MockMacroRepo_Get_Call) RunAndReturn added in v0.7.0

type PrintMsg

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

func NewPrintMsg

func NewPrintMsg(msg core.Message) *PrintMsg

NewPrintMsg creates a new PrintMsg instance with the provided core.Message. It takes a msg parameter of type core.Message, representing the message to be printed. It returns a pointer to a PrintMsg struct initialized with the given message.

func (*PrintMsg) Execute

func (c *PrintMsg) Execute(exCtx core.ExecutionContext) (core.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

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

func NewRepeatCommand

func NewRepeatCommand(times int, subCommand core.Executer) *RepeatCommand

NewRepeatCommand creates a new RepeatCommand to execute a sub-command multiple times. It takes times of type int, which specifies the number of repetitions, and subCommand of type core.Executer to repeat. It returns a pointer to a RepeatCommand initialized with the given subCommand and times.

func (*RepeatCommand) Execute

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

Execute executes the RepeatCommand and returns a core.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

NewSend creates a new Send command with the provided request string. It takes a single parameter request of type string. It returns a pointer to a Send instance initialized with the given request.

func (*Send) Execute

func (c *Send) Execute(exCtx core.ExecutionContext) (core.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 core.Executer interface.

type Sequence

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

func NewSequence

func NewSequence(subCommands []core.Executer) *Sequence

NewSequence creates a new Sequence containing a list of sub-commands. It takes subCommands, a slice of core.Executer, which represents the commands to be executed in order. It returns a pointer to a Sequence that will execute the sub-commands sequentially.

func (*Sequence) Execute

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

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

type SleepCommand

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

func NewSleepCommand

func NewSleepCommand(duration time.Duration) *SleepCommand

NewSleepCommand creates a new SleepCommand that pauses execution for a specified duration. It takes a duration parameter of type time.Duration. It returns a pointer to a SleepCommand instance.

func (*SleepCommand) Execute

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

type Templates added in v0.7.1

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

func NewMacro

func NewMacro(rawTemplates []string) (*Templates, error)

NewMacro creates a new Templates instance by parsing a list of string templates. It takes a parameter templates of type []string, representing raw string templates. It returns a pointer to a Templates instance populated with parsed templates. It returns an error if any of the provided templates fail to parse.

func (*Templates) GetExecuter added in v0.7.1

func (t *Templates) GetExecuter(args []string) (core.Executer, error)

GetExecuter generates an Executer based on the provided arguments and the templates in the Templates list. It takes args of type []string, representing input arguments for template execution. It returns a core.Executer initialized with the evaluated templates or an error if template execution fails. It returns an error if a template execution fails or if command creation from the template output fails. If a single template is evaluated, it returns the respective command; otherwise, returns a sequence of commands.

type WaitForResp

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

func NewWaitForResp

func NewWaitForResp(timeout time.Duration) *WaitForResp

NewWaitForResp creates a new WaitForResp command with the specified timeout duration. It takes a single parameter timeout of type time.Duration, determining how long to wait for a response. It returns a pointer to a WaitForResp instance.

func (*WaitForResp) Execute

func (c *WaitForResp) Execute(exCtx core.ExecutionContext) (core.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