{"modulePath":"github.com/windsorcli/cli","version":"v0.7.1","isLatest":false,"isStandardLibrary":false,"goos":"linux","goarch":"amd64","docs":"# package shell\n\n## Constants\n\n```go\nconst SessionTokenPrefix = \".session.\"\n```\nSessionTokenPrefix is the prefix used for session token files\n\n## Types\n\n```go\ntype DefaultShell struct {\n\tShell\n\t// contains filtered or unexported fields\n}\n```\nDefaultShell is the default implementation of the Shell interface\n\n```go\nfunc NewDefaultShell(injector di.Injector) *DefaultShell\n```\nNewDefaultShell creates a new instance of DefaultShell\n\n```go\nfunc (s *DefaultShell) AddCurrentDirToTrustedFile() error\n```\nAddCurrentDirToTrustedFile adds the current directory to a trusted list stored in a file. Creates necessary directories if they don't exist. Checks if the directory is already trusted before adding.\n\n```go\nfunc (s *DefaultShell) CheckResetFlags() (bool, error)\n```\nCheckResetFlags checks if a reset signal file exists for the current session token. It returns true if the specific session token file exists and always removes all .session.\\* files.\n\n```go\nfunc (s *DefaultShell) CheckTrustedDirectory() error\n```\nCheckTrustedDirectory verifies if the current directory is in the trusted file list.\n\n```go\nfunc (s *DefaultShell) Exec(command string, args ...string) (string, error)\n```\nExec runs a command with args, capturing stdout and stderr. It prints output and returns stdout as a string. If the command is \"sudo\", it connects stdin to the terminal for password input. All output is scrubbed to remove registered secrets before being displayed or returned.\n\n```go\nfunc (s *DefaultShell) ExecProgress(message string, command string, args ...string) (string, error)\n```\nExecProgress is a method of the DefaultShell struct that executes a command with a progress indicator. It takes a message, a command, and arguments, using the Exec method if verbose mode is enabled. Otherwise, it captures stdout and stderr with pipes and uses a spinner to show progress. The method returns the command's stdout as a string and any error encountered.\n\n```go\nfunc (s *DefaultShell) ExecSilent(command string, args ...string) (string, error)\n```\nExecSilent is a method that runs a command quietly, capturing its output. It returns the command's stdout as a string and any error encountered.\n\n```go\nfunc (s *DefaultShell) ExecSudo(message string, command string, args ...string) (string, error)\n```\nExecSudo runs a command with 'sudo', ensuring elevated privileges. It handles password prompts by connecting to the terminal and captures the command's output. If verbose mode is enabled, it prints a message to stderr. The function returns the command's stdout or an error if execution fails.\n\n```go\nfunc (s *DefaultShell) GetProjectRoot() (string, error)\n```\nGetProjectRoot finds the project root. It checks for a cached root first. If not found, it looks for \"windsor.yaml\" or \"windsor.yml\" in the current directory and its parents up to a maximum depth. Returns the root path or an empty string if not found.\n\n```go\nfunc (s *DefaultShell) GetSessionToken() (string, error)\n```\nGetSessionToken retrieves or generates a session token. It first checks if a token is already stored in memory. If not, it looks for a token in the environment variable. If no token is found in the environment, it generates a new token.\n\n```go\nfunc (s *DefaultShell) Initialize() error\n```\nInitialize initializes the shell\n\n```go\nfunc (s *DefaultShell) InstallHook(shellName string) error\n```\nInstallHook sets up a shell hook for a specified shell using a template with the Windsor path. It returns an error if the shell is unsupported. For PowerShell, it formats the script into a single line.\n\n```go\nfunc (s *DefaultShell) PrintAlias(aliases map[string]string)\n```\nPrintAlias prints sorted aliases. Empty values print unalias; non-empty print alias with key and value.\n\n```go\nfunc (s *DefaultShell) PrintEnvVars(envVars map[string]string, export bool)\n```\nPrintEnvVars is a platform-specific method that will be implemented by Unix/Windows-specific files The export parameter controls whether to use OS-specific export commands or plain KEY=value format\n\n```go\nfunc (s *DefaultShell) RegisterSecret(value string)\n```\nRegisterSecret adds a secret value to the internal list of secrets that will be scrubbed from all command output. Empty strings are ignored to prevent unnecessary processing. Duplicate values are automatically filtered out to maintain list efficiency.\n\n```go\nfunc (s *DefaultShell) Reset(quiet ...bool)\n```\nReset removes all managed environment variables and aliases. It uses the environment variables \"WINDSOR\\_MANAGED\\_ENV\" and \"WINDSOR\\_MANAGED\\_ALIAS\" to retrieve the previous set of managed environment variables and aliases, respectively. These environment variables represent the previous set of managed values that need to be reset. The optional quiet parameter controls whether shell commands are printed during reset.\n\n```go\nfunc (s *DefaultShell) ResetSessionToken()\n```\nResetSessionToken resets the session token - used primarily for testing\n\n```go\nfunc (s *DefaultShell) SetVerbosity(verbose bool)\n```\nSetVerbosity sets the verbosity flag\n\n```go\nfunc (s *DefaultShell) UnsetAlias(aliases []string)\n```\nUnsetAlias generates individual unalias commands for each alias in Unix shells. It prints a separate 'unalias' command for each alias name provided. If the input slice is empty, no output is produced.\n\n```go\nfunc (s *DefaultShell) UnsetEnvs(envVars []string)\n```\nUnsetEnvs generates a single unset command for multiple environment variables in Unix shells. It prints a single 'unset' command with all provided variable names separated by spaces. If the input slice is empty, no output is produced.\n\n```go\nfunc (s *DefaultShell) WriteResetToken() (string, error)\n```\nWriteResetToken writes a reset token file based on the WINDSOR\\_SESSION\\_TOKEN environment variable. If the environment variable doesn't exist, no file is written. Returns the path to the written file or an empty string if no file was written.\n\n```go\ntype HookContext struct {\n\t// SelfPath is the unescaped absolute path to direnv\n\tSelfPath string\n}\n```\nHookContext are the variables available during hook template evaluation\n\n```go\ntype MockShell struct {\n\tDefaultShell\n\tInitializeFunc                 func() error\n\tPrintEnvVarsFunc               func(envVars map[string]string, export bool)\n\tPrintAliasFunc                 func(envVars map[string]string)\n\tGetProjectRootFunc             func() (string, error)\n\tExecFunc                       func(command string, args ...string) (string, error)\n\tExecSilentFunc                 func(command string, args ...string) (string, error)\n\tExecProgressFunc               func(message string, command string, args ...string) (string, error)\n\tExecSudoFunc                   func(message string, command string, args ...string) (string, error)\n\tInstallHookFunc                func(shellName string) error\n\tSetVerbosityFunc               func(verbose bool)\n\tAddCurrentDirToTrustedFileFunc func() error\n\tCheckTrustedDirectoryFunc      func() error\n\tUnsetEnvsFunc                  func(envVars []string)\n\tUnsetAliasFunc                 func(aliases []string)\n\tWriteResetTokenFunc            func() (string, error)\n\tGetSessionTokenFunc            func() (string, error)\n\tCheckResetFlagsFunc            func() (bool, error)\n\tResetFunc                      func(...bool)\n\tRegisterSecretFunc             func(value string)\n}\n```\n\n```go\nfunc NewMockShell(injectors ...di.Injector) *MockShell\n```\nNewMockShell creates a new instance of MockShell. If injector is provided, it sets the injector on MockShell.\n\n```go\nfunc (s *MockShell) AddCurrentDirToTrustedFile() error\n```\nAddCurrentDirToTrustedFile calls the custom AddCurrentDirToTrustedFileFunc if provided.\n\n```go\nfunc (s *MockShell) CheckResetFlags() (bool, error)\n```\nCheckResetFlags checks if a reset signal file exists for the current session\n\n```go\nfunc (s *MockShell) CheckTrustedDirectory() error\n```\nCheckTrustedDirectory calls the custom CheckTrustedDirectoryFunc if provided.\n\n```go\nfunc (s *MockShell) Exec(command string, args ...string) (string, error)\n```\nExec calls the custom ExecFunc if provided.\n\n```go\nfunc (s *MockShell) ExecProgress(message string, command string, args ...string) (string, error)\n```\nExecProgress calls the custom ExecProgressFunc if provided.\n\n```go\nfunc (s *MockShell) ExecSilent(command string, args ...string) (string, error)\n```\nExecSilent calls the custom ExecSilentFunc if provided.\n\n```go\nfunc (s *MockShell) ExecSudo(message string, command string, args ...string) (string, error)\n```\nExecSudo calls the custom ExecSudoFunc if provided.\n\n```go\nfunc (s *MockShell) GetProjectRoot() (string, error)\n```\nGetProjectRoot calls the custom GetProjectRootFunc if provided.\n\n```go\nfunc (s *MockShell) GetSessionToken() (string, error)\n```\nGetSessionToken retrieves or generates a session token\n\n```go\nfunc (s *MockShell) Initialize() error\n```\nInitialize calls the custom InitializeFunc if provided.\n\n```go\nfunc (s *MockShell) InstallHook(shellName string) error\n```\nInstallHook calls the custom InstallHook if provided.\n\n```go\nfunc (s *MockShell) PrintAlias(envVars map[string]string)\n```\nPrintAlias calls the custom PrintAliasFunc if provided.\n\n```go\nfunc (s *MockShell) PrintEnvVars(envVars map[string]string, export bool)\n```\nPrintEnvVars calls the custom PrintEnvVarsFunc if provided.\n\n```go\nfunc (s *MockShell) RegisterSecret(value string)\n```\nRegisterSecret calls the custom RegisterSecretFunc if provided.\n\n```go\nfunc (s *MockShell) Reset(quiet ...bool)\n```\nReset calls the custom ResetFunc if provided.\n\n```go\nfunc (s *MockShell) SetVerbosity(verbose bool)\n```\nSetVerbosity calls the custom SetVerbosityFunc if provided.\n\n```go\nfunc (s *MockShell) UnsetAlias(aliases []string)\n```\nUnsetAlias calls the custom UnsetAliasFunc if provided.\n\n```go\nfunc (s *MockShell) UnsetEnvs(envVars []string)\n```\nUnsetEnvs calls the custom UnsetEnvsFunc if provided.\n\n```go\nfunc (s *MockShell) WriteResetToken() (string, error)\n```\nWriteResetToken writes a reset token file\n\n```go\ntype SecureShell struct {\n\tDefaultShell\n\t// contains filtered or unexported fields\n}\n```\n\n```go\nfunc NewSecureShell(injector di.Injector) *SecureShell\n```\nNewSecureShell creates a new instance of SecureShell.\n\n```go\nfunc (s *SecureShell) Exec(command string, args ...string) (string, error)\n```\nExec executes a command on the remote host via SSH and returns its output as a string.\n\n```go\nfunc (s *SecureShell) ExecProgress(message string, command string, args ...string) (string, error)\n```\nExecProgress executes a command and returns its output as a string\n\n```go\nfunc (s *SecureShell) ExecSilent(command string, args ...string) (string, error)\n```\nExecSilent executes a command and returns its output as a string without printing to stdout or stderr\n\n```go\nfunc (s *SecureShell) Initialize() error\n```\nInitialize initializes the SecureShell instance.\n\n```go\ntype Shell interface {\n\tInitialize() error\n\tSetVerbosity(verbose bool)\n\tPrintEnvVars(envVars map[string]string, export bool)\n\tPrintAlias(envVars map[string]string)\n\tGetProjectRoot() (string, error)\n\tExec(command string, args ...string) (string, error)\n\tExecSilent(command string, args ...string) (string, error)\n\tExecSudo(message string, command string, args ...string) (string, error)\n\tExecProgress(message string, command string, args ...string) (string, error)\n\tInstallHook(shellName string) error\n\tAddCurrentDirToTrustedFile() error\n\tCheckTrustedDirectory() error\n\tUnsetEnvs(envVars []string)\n\tUnsetAlias(aliases []string)\n\tWriteResetToken() (string, error)\n\tGetSessionToken() (string, error)\n\tCheckResetFlags() (bool, error)\n\tReset(quiet ...bool)\n\tRegisterSecret(value string)\n}\n```\nShell is the interface that defines shell operations.\n\n```go\ntype Shims struct {\n\t// OS operations\n\tGetwd      func() (string, error)\n\tStat       func(name string) (os.FileInfo, error)\n\tExecutable func() (string, error)\n\n\t// Standard I/O operations\n\tStderr    func() io.Writer\n\tSetStderr func(w io.Writer)\n\tStdout    func() io.Writer\n\tSetStdout func(w io.Writer)\n\tPipe      func() (*os.File, *os.File, error)\n\n\t// Shell operations\n\tUnsetEnvs  func(envVars []string)\n\tUnsetAlias func(aliases []string)\n\n\t// Exec operations\n\tCommand     func(name string, arg ...string) *exec.Cmd\n\tEnviron     func() []string\n\tLookPath    func(file string) (string, error)\n\tOpenFile    func(name string, flag int, perm os.FileMode) (*os.File, error)\n\tWriteFile   func(name string, data []byte, perm os.FileMode) error\n\tReadFile    func(name string) ([]byte, error)\n\tMkdirAll    func(path string, perm os.FileMode) error\n\tRemove      func(name string) error\n\tRemoveAll   func(path string) error\n\tChdir       func(dir string) error\n\tSetenv      func(key, value string) error\n\tGetenv      func(key string) string\n\tUserHomeDir func() (string, error)\n\n\t// Exec operations\n\tCmdRun     func(cmd *exec.Cmd) error\n\tCmdStart   func(cmd *exec.Cmd) error\n\tCmdWait    func(cmd *exec.Cmd) error\n\tStdoutPipe func(cmd *exec.Cmd) (io.ReadCloser, error)\n\tStderrPipe func(cmd *exec.Cmd) (io.ReadCloser, error)\n\tStdinPipe  func(cmd *exec.Cmd) (io.WriteCloser, error)\n\n\t// Template operations\n\tNewTemplate     func(name string) *template.Template\n\tTemplateParse   func(tmpl *template.Template, text string) (*template.Template, error)\n\tTemplateExecute func(tmpl *template.Template, wr io.Writer, data any) error\n\tExecuteTemplate func(tmpl *template.Template, data any) error\n\n\t// Bufio operations\n\tNewScanner  func(r io.Reader) *bufio.Scanner\n\tScannerScan func(scanner *bufio.Scanner) bool\n\tScannerErr  func(scanner *bufio.Scanner) error\n\tScannerText func(scanner *bufio.Scanner) string\n\tNewWriter   func(w io.Writer) *bufio.Writer\n\n\t// Filepath operations\n\tGlob func(pattern string) ([]string, error)\n\tJoin func(elem ...string) string\n\n\t// Random operations\n\tRandRead func(b []byte) (n int, err error)\n}\n```\nShims provides mockable wrappers around system and runtime functions\n\n```go\nfunc NewShims() *Shims\n```\nNewShims creates a new Shims instance with default implementations\n\n","path":"github.com/windsorcli/cli/pkg/shell","name":"shell","synopsis":"","isRedistributable":true}
