cmdutil

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: Apache-2.0 Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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.

func New

func New(version string) *Factory

New builds a Factory bound to the process streams.

func (*Factory) Debugf

func (f *Factory) Debugf(format string, args ...any)

Debugf writes one diagnostic line to ErrOut when LFED_DEBUG is set.

func (*Factory) Output

func (f *Factory) Output() (output.Mode, error)

Output returns the validated -o mode. --jq implies json: the filter runs over the JSON document, so a table or yaml request alongside it is an error rather than a silent override.

type IOStreams

type IOStreams struct {
	In     io.Reader
	Out    io.Writer
	ErrOut io.Writer
}

IOStreams are the process streams. Tests replace them with buffers.

type OutputCapture

type OutputCapture struct {
	Real io.Writer
	// contains filtered or unexported fields
}

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.

func (*OutputCapture) Write

func (c *OutputCapture) Write(p []byte) (int, error)

Jump to

Keyboard shortcuts

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