cmdctx

package
v1.6.16 Latest Latest
Warning

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

Go to latest
Published: May 28, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package cmdctx threads the resolved auto-approve policy from the root command's PersistentPreRunE down to every Cobra subcommand's Run via a typed context key. Pure plumbing; the policy itself lives in internal/approval.

Why a separate package: keeping the context-key type unexported here and exposing only With/From accessors prevents accidental cross-package shadow keys, and lets the approval package stay focused on policy resolution without leaking Cobra-shaped helpers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Approval

func Approval(cmd *cobra.Command) approval.Resolved

Approval is the Cobra-shaped sugar: read the Resolved off the command's own context. Equivalent to ApprovalFromContext(cmd.Context()) but reads more naturally at the call site of a Run function.

func ApprovalFromContext

func ApprovalFromContext(ctx context.Context) approval.Resolved

ApprovalFromContext returns the Resolved stashed by WithApproval. A context without one yields the zero value — Auto=false, ConfirmFloor at the zero tier — which is the safe cautious default (every approval.Confirm call falls through to the interactive prompt).

func WithApproval

func WithApproval(ctx context.Context, r approval.Resolved) context.Context

WithApproval returns a child context carrying r. main.go's PersistentPreRunE calls this once at startup and SetContext's the result onto the executing command so every descendant Run sees the same Resolved.

Types

This section is empty.

Jump to

Keyboard shortcuts

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