exec

package
v0.69.13 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2024 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package exec runs external commands. It wraps exec.Cmd package with support for allocating a pseudo-terminal.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PrepareConsole

func PrepareConsole(_ log.Logger)

PrepareConsole is run at the start of the application to set up the console.

Types

type Cmd

type Cmd struct {
	*exec.Cmd
	// contains filtered or unexported fields
}

Cmd is a command type.

func Command

func Command(name string, args ...string) *Cmd

Command returns the `Cmd` struct to execute the named program with the given arguments.

func (*Cmd) Configure

func (cmd *Cmd) Configure(opts ...Option)

Configure sets options to the `Cmd`.

func (*Cmd) ForwardSignal

func (cmd *Cmd) ForwardSignal(ctx context.Context, sig os.Signal)

ForwardSignal forwards a given `sig` with a delay if cmd.forwardSignalDelay is greater than 0, and if the same signal is received again, it is forwarded immediately.

func (*Cmd) RegisterGracefullyShutdown

func (cmd *Cmd) RegisterGracefullyShutdown(ctx context.Context) func()

RegisterGracefullyShutdown registers a graceful shutdown for the command in two ways:

  1. If the context cancel contains a cause with a signal, this means that Terragrunt received the signal from the OS, since our executed command may also receive the same signal, we need to give the command time to gracefully shutting down, to avoid the command receiving this signal twice. Thus we will send the signal to the executed command with a delay or immediately if Terragrunt receives this same signal again.
  2. If the context does not contain any causes, this means that there was some failure and we need to terminate all executed commands, in this situation we are sure that commands did not receive any signal, so we send them an interrupt signal immediately.

func (*Cmd) SendSignal

func (cmd *Cmd) SendSignal(sig os.Signal)

SendSignal sends the given `sig` to the executed command.

func (*Cmd) Start

func (cmd *Cmd) Start() error

Start starts the specified command but does not wait for it to complete.

type Option

type Option func(*Cmd)

Option is type for passing options to the Cmd.

func WithEnv

func WithEnv(env map[string]string) Option

WithEnv sets envs to the Cmd.

func WithForwardSignalDelay

func WithForwardSignalDelay(delay time.Duration) Option

WithForwardSignalDelay sets forwarding signal delay to the Cmd.

func WithLogger

func WithLogger(logger log.Logger) Option

WithLogger sets Logger to the Cmd.

func WithUsePTY

func WithUsePTY(state bool) Option

WithUsePTY enables a pty for the Cmd.

Jump to

Keyboard shortcuts

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