Documentation
¶
Overview ¶
Package shell provides functions to run shell commands and Terraform commands.
Index ¶
- Constants
- Variables
- func ContextWithTerraformCommandHook(ctx context.Context, fn RunShellCommandFunc) context.Context
- func ExplainError(err error) string
- func GitLastReleaseTag(ctx context.Context, opts *options.TerragruntOptions, gitRepo *url.URL) (string, error)
- func GitRepoTags(ctx context.Context, opts *options.TerragruntOptions, gitRepo *url.URL) ([]string, error)
- func GitTopLevelDir(ctx context.Context, terragruntOptions *options.TerragruntOptions, path string) (string, error)
- func LastReleaseTag(tags []string) string
- func PrepareConsole(terragruntOptions *options.TerragruntOptions)
- func PromptUserForInput(ctx context.Context, prompt string, ...) (string, error)
- func PromptUserForYesNo(ctx context.Context, prompt string, ...) (bool, error)
- func RegisterSignalHandler(notifyFn func(os.Signal), sigs ...os.Signal)
- func RunShellCommand(ctx context.Context, terragruntOptions *options.TerragruntOptions, ...) error
- func RunShellCommandWithOutput(ctx context.Context, opts *options.TerragruntOptions, workingDir string, ...) (*util.CmdOutput, error)
- func RunTerraformCommand(ctx context.Context, terragruntOptions *options.TerragruntOptions, ...) error
- func RunTerraformCommandWithOutput(ctx context.Context, terragruntOptions *options.TerragruntOptions, ...) (*util.CmdOutput, error)
- type RunShellCommandFunc
- type SignalsForwarder
Constants ¶
const ( TerraformCommandContextKey ctxKey = iota RunCmdCacheContextKey ctxKey = iota )
const SignalForwardingDelay = time.Second * 30
SignalForwardingDelay is the time to wait before forwarding the signal to the subcommand.
The signal can be sent to the main process (only `terragrunt`) as well as the process group (`terragrunt` and `terraform`), for example: kill -INT <pid> # sends SIGINT only to the main process kill -INT -<pid> # sends SIGINT to the process group Since we cannot know how the signal is sent, we should give `tofu`/`terraform` time to gracefully exit if it receives the signal directly from the shell, to avoid sending the second interrupt signal to `tofu`/`terraform`.
Variables ¶
Functions ¶
func ContextWithTerraformCommandHook ¶
func ContextWithTerraformCommandHook(ctx context.Context, fn RunShellCommandFunc) context.Context
func ExplainError ¶
ExplainError will try to explain the error to the user, if we know how to do so.
func GitLastReleaseTag ¶
func GitLastReleaseTag(ctx context.Context, opts *options.TerragruntOptions, gitRepo *url.URL) (string, error)
GitLastReleaseTag - fetch git repository last release tag
func GitRepoTags ¶
func GitRepoTags(ctx context.Context, opts *options.TerragruntOptions, gitRepo *url.URL) ([]string, error)
GitRepoTags - fetch git repository tags from passed url
func GitTopLevelDir ¶
func GitTopLevelDir(ctx context.Context, terragruntOptions *options.TerragruntOptions, path string) (string, error)
GitTopLevelDir - fetch git repository path from passed directory
func LastReleaseTag ¶
LastReleaseTag - return last release tag from passed tags slice.
func PrepareConsole ¶
func PrepareConsole(terragruntOptions *options.TerragruntOptions)
func PromptUserForInput ¶
func PromptUserForInput(ctx context.Context, prompt string, terragruntOptions *options.TerragruntOptions) (string, error)
PromptUserForInput prompts the user for text in the CLI. Returns the text entered by the user.
func PromptUserForYesNo ¶
func PromptUserForYesNo(ctx context.Context, prompt string, terragruntOptions *options.TerragruntOptions) (bool, error)
PromptUserForYesNo prompts the user for a yes/no response and return true if they entered yes.
func RegisterSignalHandler ¶
RegisterSignalHandler registers a handler of interrupt signal from the OS. When signal is receiving, it calls the given callback func `notifyFn`.
func RunShellCommand ¶
func RunShellCommand(ctx context.Context, terragruntOptions *options.TerragruntOptions, command string, args ...string) error
RunShellCommand runs the given shell command.
func RunShellCommandWithOutput ¶
func RunShellCommandWithOutput( ctx context.Context, opts *options.TerragruntOptions, workingDir string, suppressStdout bool, allocatePseudoTty bool, command string, args ...string, ) (*util.CmdOutput, error)
RunShellCommandWithOutput runs the specified shell command with the specified arguments.
Connect the command's stdin, stdout, and stderr to the currently running app. The command can be executed in a custom working directory by using the parameter `workingDir`. Terragrunt working directory will be assumed if empty string.
func RunTerraformCommand ¶
func RunTerraformCommand(ctx context.Context, terragruntOptions *options.TerragruntOptions, args ...string) error
RunTerraformCommand runs the given Terraform command.
func RunTerraformCommandWithOutput ¶
func RunTerraformCommandWithOutput(ctx context.Context, terragruntOptions *options.TerragruntOptions, args ...string) (*util.CmdOutput, error)
RunTerraformCommandWithOutput runs the given Terraform command, writing its stdout/stderr to the terminal AND returning stdout/stderr to this method's caller
Types ¶
type RunShellCommandFunc ¶
type RunShellCommandFunc func(ctx context.Context, opts *options.TerragruntOptions, args cli.Args) (*util.CmdOutput, error)
RunShellCommandFunc is a context value for `TerraformCommandContextKey` key, used to intercept shell commands.
func TerraformCommandHookFromContext ¶
func TerraformCommandHookFromContext(ctx context.Context) RunShellCommandFunc
TerraformCommandHookFromContext returns `RunShellCommandFunc` from the context if it has been set, otherwise returns nil.
type SignalsForwarder ¶
func NewSignalsForwarder ¶
func NewSignalsForwarder(signals []os.Signal, c *exec.Cmd, logger log.Logger, cmdChannel chan error) SignalsForwarder
NewSignalsForwarder Forwards signals to a command, waiting for the command to finish.
func (*SignalsForwarder) Close ¶
func (signalChannel *SignalsForwarder) Close() error