utils

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2025 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterCommonTools

func RegisterCommonTools(s *server.MCPServer)

func RegisterDateTimeTools

func RegisterDateTimeTools(s *server.MCPServer)

func RunCommand

func RunCommand(command string, args []string) (string, error)

RunCommand executes a command and returns output or error with OTEL tracing

func RunCommandWithContext

func RunCommandWithContext(ctx context.Context, command string, args []string) (string, error)

RunCommandWithContext executes a command with context and returns output or error with OTEL tracing

func WithShellExecutor

func WithShellExecutor(ctx context.Context, executor ShellExecutor) context.Context

WithShellExecutor returns a context with the given shell executor

Types

type DefaultShellExecutor

type DefaultShellExecutor struct{}

DefaultShellExecutor implements ShellExecutor using os/exec

func (*DefaultShellExecutor) Exec

func (e *DefaultShellExecutor) Exec(ctx context.Context, command string, args ...string) ([]byte, error)

Exec executes a command using os/exec.CommandContext

type MockCommandCall

type MockCommandCall struct {
	Command string
	Args    []string
}

MockCommandCall represents a logged command execution

type MockCommandResult

type MockCommandResult struct {
	Output []byte
	Error  error
}

MockCommandResult represents the expected result of a mocked command

type MockShellExecutor

type MockShellExecutor struct {
	// Commands maps command+args to expected output and error
	Commands map[string]MockCommandResult
	// CallLog keeps track of all executed commands for verification
	CallLog []MockCommandCall
	// PartialMatchers allows partial matching for dynamic arguments
	PartialMatchers []PartialMatcher
}

MockShellExecutor implements ShellExecutor for testing

func NewMockShellExecutor

func NewMockShellExecutor() *MockShellExecutor

NewMockShellExecutor creates a new mock shell executor for testing

func (*MockShellExecutor) AddCommand

func (m *MockShellExecutor) AddCommand(command string, args []string, output []byte, err error)

AddCommand adds a command mock

func (*MockShellExecutor) AddCommandString

func (m *MockShellExecutor) AddCommandString(command string, args []string, output string, err error)

AddCommandString is a convenience method for adding string output

func (*MockShellExecutor) AddPartialMatcher

func (m *MockShellExecutor) AddPartialMatcher(command string, args []string, output []byte, err error)

AddPartialMatcher adds a partial matcher for dynamic arguments

func (*MockShellExecutor) AddPartialMatcherString

func (m *MockShellExecutor) AddPartialMatcherString(command string, args []string, output string, err error)

AddPartialMatcherString is a convenience method for adding string output with partial matching

func (*MockShellExecutor) Exec

func (m *MockShellExecutor) Exec(ctx context.Context, command string, args ...string) ([]byte, error)

Exec executes a mocked command

func (*MockShellExecutor) GetCallLog

func (m *MockShellExecutor) GetCallLog() []MockCommandCall

GetCallLog returns the log of all command calls

func (*MockShellExecutor) Reset

func (m *MockShellExecutor) Reset()

Reset clears the mock state

type PartialMatcher

type PartialMatcher struct {
	Command string
	Args    []string // Use "*" for wildcard matching
	Result  MockCommandResult
}

PartialMatcher represents a partial command matcher for dynamic arguments

type ShellExecutor

type ShellExecutor interface {
	Exec(ctx context.Context, command string, args ...string) (output []byte, err error)
}

ShellExecutor defines the interface for executing shell commands

func GetShellExecutor

func GetShellExecutor(ctx context.Context) ShellExecutor

GetShellExecutor retrieves the shell executor from context, or returns default

Jump to

Keyboard shortcuts

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