shell

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2024 License: MPL-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DefaultShell

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

DefaultShell is the default implementation of the Shell interface

func NewDefaultShell

func NewDefaultShell(injector di.Injector) *DefaultShell

NewDefaultShell creates a new instance of DefaultShell

func (*DefaultShell) Exec

func (s *DefaultShell) Exec(command string, args ...string) (string, error)

Exec executes a command and returns its output as a string

func (*DefaultShell) ExecProgress

func (s *DefaultShell) ExecProgress(message string, command string, args ...string) (string, error)

ExecProgress executes a command and returns its output as a string while displaying progress status

func (*DefaultShell) ExecSilent

func (s *DefaultShell) ExecSilent(command string, args ...string) (string, error)

ExecSilent executes a command and returns its output as a string without printing to stdout or stderr

func (*DefaultShell) ExecSudo

func (s *DefaultShell) ExecSudo(message string, command string, args ...string) (string, error)

ExecSudo executes a command with sudo if not already present and returns its output while suppressing it from being printed

func (*DefaultShell) GetProjectRoot

func (s *DefaultShell) GetProjectRoot() (string, error)

GetProjectRoot retrieves the project root directory

func (*DefaultShell) Initialize

func (s *DefaultShell) Initialize() error

Initialize initializes the shell

func (*DefaultShell) InstallHook

func (s *DefaultShell) InstallHook(shellName string) error

InstallHook installs a shell hook if it exists for the given shell name. It executes the hook command silently and returns an error if the shell is unsupported.

func (*DefaultShell) PrintAlias

func (s *DefaultShell) PrintAlias(aliases map[string]string) error

PrintAlias prints the aliases for the shell.

func (*DefaultShell) PrintEnvVars

func (s *DefaultShell) PrintEnvVars(envVars map[string]string) error

PrintEnvVars prints the provided environment variables in a sorted order. If the value of an environment variable is an empty string, it will print an unset command.

type HookContext

type HookContext struct {
	// SelfPath is the unescaped absolute path to direnv
	SelfPath string
}

HookContext are the variables available during hook template evaluation

type InstallHook

type InstallHook interface {
	Execute() error
}

type MockShell

type MockShell struct {
	DefaultShell
	InitializeFunc     func() error
	PrintEnvVarsFunc   func(envVars map[string]string) error
	PrintAliasFunc     func(envVars map[string]string) error
	GetProjectRootFunc func() (string, error)
	ExecFunc           func(command string, args ...string) (string, error)
	ExecSilentFunc     func(command string, args ...string) (string, error)
	ExecProgressFunc   func(message string, command string, args ...string) (string, error)
	ExecSudoFunc       func(message string, command string, args ...string) (string, error)
	InstallHookFunc    func(shellName string) error
}

MockShell is a struct that simulates a shell environment for testing purposes.

func NewMockShell

func NewMockShell(injectors ...di.Injector) *MockShell

NewMockShell creates a new instance of MockShell. If injector is provided, it sets the injector on MockShell.

func (*MockShell) Exec

func (s *MockShell) Exec(command string, args ...string) (string, error)

Exec calls the custom ExecFunc if provided.

func (*MockShell) ExecProgress

func (s *MockShell) ExecProgress(message string, command string, args ...string) (string, error)

ExecProgress calls the custom ExecProgressFunc if provided.

func (*MockShell) ExecSilent

func (s *MockShell) ExecSilent(command string, args ...string) (string, error)

ExecSilent calls the custom ExecSilentFunc if provided.

func (*MockShell) ExecSudo

func (s *MockShell) ExecSudo(message string, command string, args ...string) (string, error)

ExecSudo calls the custom ExecSudoFunc if provided.

func (*MockShell) GetProjectRoot

func (s *MockShell) GetProjectRoot() (string, error)

GetProjectRoot calls the custom GetProjectRootFunc if provided.

func (*MockShell) Initialize

func (s *MockShell) Initialize() error

Initialize calls the custom InitializeFunc if provided.

func (*MockShell) InstallHook

func (s *MockShell) InstallHook(shellName string) error

InstallHook calls the custom InstallHook if provided.

func (*MockShell) PrintAlias

func (s *MockShell) PrintAlias(envVars map[string]string) error

PrintAlias calls the custom PrintAliasFunc if provided.

func (*MockShell) PrintEnvVars

func (s *MockShell) PrintEnvVars(envVars map[string]string) error

PrintEnvVars calls the custom PrintEnvVarsFunc if provided.

type SecureShell

type SecureShell struct {
	DefaultShell
	// contains filtered or unexported fields
}

SecureShell implements the Shell interface using SSH.

func NewSecureShell

func NewSecureShell(injector di.Injector) *SecureShell

NewSecureShell creates a new instance of SecureShell.

func (*SecureShell) Exec

func (s *SecureShell) Exec(command string, args ...string) (string, error)

Exec executes a command on the remote host via SSH and returns its output as a string.

func (*SecureShell) ExecProgress

func (s *SecureShell) ExecProgress(message string, command string, args ...string) (string, error)

ExecProgress executes a command and returns its output as a string

func (*SecureShell) ExecSilent

func (s *SecureShell) ExecSilent(command string, args ...string) (string, error)

ExecSilent executes a command and returns its output as a string without printing to stdout or stderr

func (*SecureShell) Initialize

func (s *SecureShell) Initialize() error

Initialize initializes the SecureShell instance.

type Shell

type Shell interface {
	// Initialize initializes the shell environment
	Initialize() error
	// PrintEnvVars prints the provided environment variables
	PrintEnvVars(envVars map[string]string) error
	// PrintAlias retrieves the shell alias
	PrintAlias(envVars map[string]string) error
	// GetProjectRoot retrieves the project root directory
	GetProjectRoot() (string, error)
	// Exec executes a command with optional privilege elevation
	Exec(command string, args ...string) (string, error)
	// ExecSilent executes a command and returns its output as a string without printing to stdout or stderr
	ExecSilent(command string, args ...string) (string, error)
	// ExecSudo executes a command with sudo if not already present and returns its output as a string while suppressing it from being printed
	ExecSudo(message string, command string, args ...string) (string, error)
	// ExecProgress executes a command and returns its output as a string while displaying progress status
	ExecProgress(message string, command string, args ...string) (string, error)
	// InstallHook installs a shell hook for the specified shell name
	InstallHook(shellName string) error
}

Shell interface defines methods for shell operations

Jump to

Keyboard shortcuts

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