execmd

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: May 17, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddToContainer

func AddToContainer(ctr *dagger.Container, execCMDs []types.ContainerCommand) *dagger.Container

AddToContainer adds commands to a container. This function is useful when you want to inject commands into a container before running them.

func BuildArgs added in v0.0.3

func BuildArgs(args ...string) types.DaggerCMD

BuildArgs processes and builds a command argument list from the provided arguments. It trims spaces from each argument and splits arguments with spaces into separate arguments.

Parameters:

  • args: A variadic parameter that takes multiple strings representing command arguments.

Returns:

  • A DaggerCMD slice containing the processed arguments.

Example:

// Build arguments for a Terraform command
args := BuildArgs("plan", "-var 'foo=bar'", "apply --auto-approve")
// args now contains: ["plan", "-var", "'foo=bar'", "apply", "--auto-approve"]

// Build arguments for a Go command
args = BuildArgs("run", "main.go", "--verbose")
// args now contains: ["run", "main.go", "--verbose"]

Types

type DaggerCMD

type DaggerCMD []string

DaggerCMD is an alias for a slice of strings representing a command.

func GenerateCommand

func GenerateCommand(command string, args ...string) (*DaggerCMD, error)

GenerateCommand generates a command with the provided arguments. It ensures that arguments with spaces are handled correctly.

Parameters:

  • command: A string representing the main command to be executed.
  • args: A variadic slice of strings representing the arguments for the command.

Returns:

  • A pointer to a DaggerCMD slice, which includes the main command followed by the provided arguments.
  • An error if the main command is empty.

Example:

// Generate a Terraform plan command
cmd, err := GenerateCommand("terraform", "plan", "-var", "foo=bar", "apply --auto-approve")
if err != nil {
    // handle error
}
// Use cmd, e.g., fmt.Println(*cmd) // Output: [terraform plan -var foo=bar apply --auto-approve]

// Generate a Go run command
cmd, err = GenerateCommand("go", "run", "main.go", "--verbose")
if err != nil {
    // handle error
}
// Use cmd, e.g., fmt.Println(*cmd) // Output: [go run main.go --verbose]

Jump to

Keyboard shortcuts

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