Documentation
¶
Overview ¶
Package cmdutil holds the Factory injected into every command package.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Factory ¶
type Factory struct {
IOStreams IOStreams
// Version is the lfed CLI semver (internal/build.Version).
Version string
// Root persistent flags. Cobra writes them before any RunE runs.
ContextFlag string // -c/--context
OutputFlag string // -o/--output
JQ string // --jq
Yes bool // --yes
InsecureStorage bool // --insecure-storage
// Debug is true when LFED_DEBUG is set. Debugf writes to ErrOut only then.
Debug bool
// Capture, when set, is the IOStreams.Out writer. --jq starts a
// capture so the JSON document can be filtered after the command ran.
Capture *OutputCapture
// Config loads $XDG_CONFIG_HOME/lfed/config.yaml.
Config func() (*config.Config, error)
// Context resolves the active context: -c, LFED_CONTEXT, config file.
Context func() (contexts.Context, error)
// Token returns a valid access token for the active context. It
// refreshes when the cached token expires within 60 seconds. The auth
// package installs it in main.
Token func(ctx context.Context) (string, error)
// Executable returns the absolute path of the running lfed binary. The
// plugin manager exports it as LFED_REEXEC.
Executable func() (string, error)
}
Factory carries shared state and lazily resolved dependencies. Command constructors take *Factory and read it at run time, not at build time, so persistent flags parsed by Cobra are visible.
type OutputCapture ¶
OutputCapture is a writer that passes through to Real until Start, then buffers until Stop. It lets --jq post-process stdout without the commands or plugins knowing.
func (*OutputCapture) Start ¶
func (c *OutputCapture) Start()
Start begins buffering. Calling it twice keeps the first buffer.
func (*OutputCapture) Stop ¶
func (c *OutputCapture) Stop() (data []byte, ok bool)
Stop ends buffering and returns what was captured; ok is false when Start was never called.