Documentation
¶
Overview ¶
Package deploy provides command execution utilities for local and remote deployments.
Package deploy provides command execution utilities for local and remote deployments.
Index ¶
- func MatchHost(target, pattern string) bool
- func ResolveSSHTarget(target, user, keyPath string) (string, string, string, string, error)
- type CommandBuilder
- type CommandExecutor
- type Executor
- func (e *Executor) CopyFile(src, dst string) error
- func (e *Executor) IsLocal() bool
- func (e *Executor) Run(command string) (string, error)
- func (e *Executor) RunSudo(command string) (string, error)
- func (e *Executor) SetCommandBuilder(builder CommandBuilder)
- func (e *Executor) SetLogger(logger Logger)
- func (e *Executor) WriteFile(path, content string) error
- type Logger
- type MockBuiltCommand
- type MockCommandBuilder
- func (b *MockCommandBuilder) BuildCommand(name string, args ...string) CommandExecutor
- func (b *MockCommandBuilder) BuildShellCommand(command string) CommandExecutor
- func (b *MockCommandBuilder) LastCommand() *MockBuiltCommand
- func (b *MockCommandBuilder) Reset()
- func (b *MockCommandBuilder) SetNextExecutor(executor *MockCommandExecutor)
- type MockCommandExecutor
- type RealCommandBuilder
- type RealCommandExecutor
- type SSHConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type CommandBuilder ¶
type CommandBuilder interface {
// BuildCommand creates a CommandExecutor for running local commands.
BuildCommand(name string, args ...string) CommandExecutor
// BuildShellCommand creates a CommandExecutor for running shell commands via sh -c.
BuildShellCommand(command string) CommandExecutor
}
CommandBuilder defines an interface for building shell commands. This abstraction enables unit testing of SSH/SCP command construction.
type CommandExecutor ¶
type CommandExecutor interface {
// Run executes the command and returns the combined output (stdout+stderr).
Run() ([]byte, error)
// SetStdin sets the stdin for the command.
SetStdin(stdin []byte)
}
CommandExecutor defines an interface for executing shell commands. This abstraction enables unit testing without real shell execution.
type Executor ¶
type Executor struct {
Target string
SSHUser string
SSHKey string
IdentityAgent string
DryRun bool
Logger Logger
CommandBuilder CommandBuilder // Injectable command builder for testability
}
Executor handles command execution on local or remote targets.
func NewExecutor ¶
NewExecutor creates a new command executor.
func (*Executor) SetCommandBuilder ¶
func (e *Executor) SetCommandBuilder(builder CommandBuilder)
SetCommandBuilder sets a custom command builder for dependency injection. This enables unit testing without real shell execution.
type Logger ¶
type Logger interface {
Debugf(format string, args ...interface{})
}
Logger defines the interface for debug logging.
type MockBuiltCommand ¶
MockBuiltCommand records details of a built command.
type MockCommandBuilder ¶
type MockCommandBuilder struct {
// Commands records all commands that were built.
Commands []MockBuiltCommand
// NextExecutor is the next executor to return. If nil, creates a default MockCommandExecutor.
NextExecutor *MockCommandExecutor
// ExecutorFactory allows creating executors dynamically based on command.
ExecutorFactory func(name string, args []string) *MockCommandExecutor
}
MockCommandBuilder implements CommandBuilder for testing.
func NewMockCommandBuilder ¶
func NewMockCommandBuilder() *MockCommandBuilder
NewMockCommandBuilder creates a new MockCommandBuilder.
func (*MockCommandBuilder) BuildCommand ¶
func (b *MockCommandBuilder) BuildCommand(name string, args ...string) CommandExecutor
BuildCommand creates a MockCommandExecutor and records the command details.
func (*MockCommandBuilder) BuildShellCommand ¶
func (b *MockCommandBuilder) BuildShellCommand(command string) CommandExecutor
BuildShellCommand creates a MockCommandExecutor for shell commands.
func (*MockCommandBuilder) LastCommand ¶
func (b *MockCommandBuilder) LastCommand() *MockBuiltCommand
LastCommand returns the most recently built command, or nil if none.
func (*MockCommandBuilder) Reset ¶
func (b *MockCommandBuilder) Reset()
Reset clears all recorded commands.
func (*MockCommandBuilder) SetNextExecutor ¶
func (b *MockCommandBuilder) SetNextExecutor(executor *MockCommandExecutor)
SetNextExecutor sets the executor to return for the next Build* call.
type MockCommandExecutor ¶
type MockCommandExecutor struct {
// Output is the output to return from Run.
Output []byte
// Err is the error to return from Run.
Err error
// Stdin holds the stdin data that was set.
Stdin []byte
// RunCalled indicates whether Run was called.
RunCalled bool
}
MockCommandExecutor implements CommandExecutor for testing.
func (*MockCommandExecutor) Run ¶
func (m *MockCommandExecutor) Run() ([]byte, error)
Run returns the configured output and error.
func (*MockCommandExecutor) SetStdin ¶
func (m *MockCommandExecutor) SetStdin(stdin []byte)
SetStdin records the stdin data.
type RealCommandBuilder ¶
type RealCommandBuilder struct{}
RealCommandBuilder implements CommandBuilder using exec.Command.
func NewRealCommandBuilder ¶
func NewRealCommandBuilder() *RealCommandBuilder
NewRealCommandBuilder creates a new RealCommandBuilder.
func (*RealCommandBuilder) BuildCommand ¶
func (b *RealCommandBuilder) BuildCommand(name string, args ...string) CommandExecutor
BuildCommand creates a CommandExecutor for the given command and arguments.
func (*RealCommandBuilder) BuildShellCommand ¶
func (b *RealCommandBuilder) BuildShellCommand(command string) CommandExecutor
BuildShellCommand creates a CommandExecutor for shell commands.
type RealCommandExecutor ¶
type RealCommandExecutor struct {
// contains filtered or unexported fields
}
RealCommandExecutor wraps exec.Cmd to implement CommandExecutor.
func (*RealCommandExecutor) Run ¶
func (r *RealCommandExecutor) Run() ([]byte, error)
Run executes the command and returns combined output.
func (*RealCommandExecutor) SetStdin ¶
func (r *RealCommandExecutor) SetStdin(stdin []byte)
SetStdin sets stdin for the command.
type SSHConfig ¶
type SSHConfig struct {
Host string
HostName string
User string
IdentityFile string
IdentityAgent string
Port string
}
SSHConfig represents parsed SSH configuration for a host.
func ParseSSHConfig ¶
ParseSSHConfig reads and parses ~/.ssh/config for the given host.
func ParseSSHConfigFrom ¶
ParseSSHConfigFrom reads and parses an SSH config file for the given host. If configPath is empty, uses ~/.ssh/config.