shell

package
v1.222.0-rc.2 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package shell provides generic helpers for launching subprocesses and interactive shells with a caller-supplied environment. It is intentionally free of any auth/secret-specific knowledge so multiple commands (e.g. `atmos auth exec`, `atmos secret exec`) can reuse it.

Index

Constants

View Source
const LevelEnvVar = "ATMOS_SHLVL"

LevelEnvVar is the environment variable tracking how deeply nested the current Atmos-managed shell is.

Variables

This section is empty.

Functions

func DecrementLevel

func DecrementLevel()

DecrementLevel decrements the ATMOS_SHLVL environment variable, stopping at 0.

func Determine

func Determine(shellOverride string, shellArgs []string) (string, []string)

Determine resolves which shell binary to launch and which arguments to pass.

The shell is taken from (in order): the explicit override, the "shell" Viper key, then a platform default (cmd.exe on Windows; bash, falling back to sh, elsewhere). When no shell args are supplied, a login shell ("-l") is used by default on Unix.

func Level

func Level() int

Level retrieves the current ATMOS_SHLVL value (0 when unset or invalid).

func RunCommand

func RunCommand(args []string, env []string) error

RunCommand executes args[0] with args[1:] using the supplied environment list, wiring stdin/stdout/stderr to the parent process.

The env list is passed to the child verbatim and must already be complete (e.g. os.Environ() + any additions) — do NOT prepend os.Environ() or convert to a map, as that would lose ordering and could collide on duplicate keys (such as Windows-style drive-scoped vars).

The child's exit code is propagated as errUtils.ExitCodeError so the root command can exit with the same status. A missing executable returns errUtils.ErrCommandNotFound with exit code 127 (the conventional shell "command not found" code), distinct from ErrUnknownSubcommand so the root handler does not mistake it for an unknown Atmos subcommand.

func SetLevel

func SetLevel(level int) error

SetLevel sets the ATMOS_SHLVL environment variable.

func StartInteractive

func StartInteractive(shellCommand string, shellArgs []string, env []string) error

StartInteractive launches an interactive shell process with the supplied environment, transferring stdin/stdout/stderr to it, and waits for the user to exit. The shell's exit code is propagated as errUtils.ExitCodeError.

Internally, os.StartProcess is used (rather than exec.Command) so the TTY is passed through directly for interactive sessions.

Types

This section is empty.

Jump to

Keyboard shortcuts

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