Documentation
¶
Overview ¶
Package platform provides OS / package-manager detection and the small set of privileged and unprivileged host operations the CLI relies on.
Index ¶
- func Dispatch(mac, linux func() error) error
- func Has(name string) bool
- func InstallPackage(pkg string) error
- func IsActiveService(unit string) bool
- func Output(name string, args ...string) (string, error)
- func OutputContext(ctx context.Context, name string, args ...string) (string, error)
- func Pick[T any](mac, linux T) (T, error)
- func RemoveFilePrivileged(path string) error
- func Run(name string, args ...string) error
- func Sudo(args ...string) error
- func SudoPrime(purpose string)
- func WriteFilePrivileged(path string, content []byte, mode os.FileMode) error
- type ExecRunner
- type OS
- type PackageManager
- type Runner
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Dispatch ¶
Dispatch runs the handler matching the current OS, erroring on unsupported platforms. It is the single place per-OS behavior branches.
func InstallPackage ¶
InstallPackage installs a package using the detected package manager.
func IsActiveService ¶
IsActiveService reports whether a systemd unit is active (Linux only).
func OutputContext ¶ added in v0.13.0
OutputContext runs a command under a context and returns its standard output. Every host reading that shells out goes through here: a check that runs out of time must fail rather than hang.
func Pick ¶ added in v0.13.0
Pick returns the value matching the current OS, erroring on unsupported platforms. It is Dispatch for the answers that are a value rather than an error, so per-OS knowledge keeps to the one branch point instead of growing a switch at every call site.
func RemoveFilePrivileged ¶
RemoveFilePrivileged removes a root-owned file, ignoring a missing file.
func Sudo ¶
Sudo runs a command with elevated privileges, prompting once if needed. When already running as root it executes the command directly.
func SudoPrime ¶
func SudoPrime(purpose string)
SudoPrime primes the sudo credential cache so subsequent privileged calls do not each prompt for a password. It is best-effort and never fatal: `sudo -v` demands a password unless *every* sudoers entry matching the user is NOPASSWD, so where sudo itself asks nothing it would still prompt — and without a TTY fail — an install every later `sudo <cmd>` would have completed. The non-interactive probe settles that without asking, and only the privileged calls themselves can say whether the host is usable.
Types ¶
type ExecRunner ¶ added in v0.3.0
type ExecRunner struct{}
ExecRunner is the production Runner. It carries no state and forwards every call to the package-level functions, so routing host steps through a Runner changes no observable behavior.
func (ExecRunner) RemoveFilePrivileged ¶ added in v0.3.0
func (ExecRunner) RemoveFilePrivileged(path string) error
func (ExecRunner) Sudo ¶ added in v0.3.0
func (ExecRunner) Sudo(args ...string) error
func (ExecRunner) WriteFilePrivileged ¶ added in v0.3.0
type PackageManager ¶
type PackageManager string
PackageManager identifies a supported package manager.
const ( // Brew is Homebrew (macOS). Brew PackageManager = "brew" // Apt is APT (Ubuntu/Debian). Apt PackageManager = "apt" )
func DetectPackageManager ¶
func DetectPackageManager() (PackageManager, error)
DetectPackageManager returns the available package manager for the host.
type Runner ¶ added in v0.3.0
type Runner interface {
Run(name string, args ...string) error
Sudo(args ...string) error
WriteFilePrivileged(path string, content []byte, mode os.FileMode) error
RemoveFilePrivileged(path string) error
}
Runner is the privileged/host exec surface the install/uninstall host steps mutate through. ExecRunner is the production adapter — each method delegates to the matching package function unchanged — so production behavior is identical; tests pass a fake that records calls to assert step ordering and rollback without touching the host.