cmdutil

package
v1.85.1 Latest Latest
Warning

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

Go to latest
Published: May 19, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const NoColorFlag = "no-color"

NoColorFlag is the persistent flag name that disables color output. Defined here so root registration and any consumer (e.g. PreRunE wiring, integration tests) reference the same string.

View Source
const PagerAnnotation = "pager"

PagerAnnotation is the cobra annotation key that marks a command as long-output and pager-eligible. Commands set

Annotations: map[string]string{cmdutil.PagerAnnotation: "true"}

instead of calling StartPager/StopPager inline. This keeps pager lifecycle out of command bodies — adding pager support to a new command is one annotation, not a 5-line copy-paste with an easily- missed defer.

Variables

This section is empty.

Functions

func ApplyNoColorFlag added in v1.17.0

func ApplyNoColorFlag(cmd *cobra.Command, ios *iostreams.IOStreams)

ApplyNoColorFlag reads --no-color off the command's flag set and, if set, flips the IOStreams color decision off. Designed for use inside PersistentPreRunE so a single registration applies across every subcommand.

Cobra walks PersistentFlags up the parent chain when resolving a flag, so passing --no-color on a leaf command (e.g. `bitbottle pr list --no-color`) still surfaces here. We deliberately do NOT call SetColorEnabled(true) when the flag is unset — leaving IOStreams as constructed lets NO_COLOR env and TTY detection keep their say.

func EnablePagerForAnnotated added in v1.12.0

func EnablePagerForAnnotated(root *cobra.Command, ios *iostreams.IOStreams)

EnablePagerForAnnotated walks the command tree rooted at root and wraps every annotated command's RunE so the pager is started before the command runs and stopped after. The pager is a no-op outside a TTY, so unmarked commands and piped invocations are unaffected.

Walking happens at registration time (call once after building the tree). The wrap is invisible to the command body — a command can still call f.IOStreams.Out directly, and gets the pager pipe for free.

func FatalIfError

func FatalIfError(err error)

func PartialWarn added in v1.73.0

func PartialWarn(w io.Writer, n int, listErr error)

PartialWarn writes a warning to w when items were collected but pagination ended with an error. Call it after rendering and before returning listErr. It is a no-op when listErr is nil or n == 0.

func RegisterNoColorFlag added in v1.17.0

func RegisterNoColorFlag(root *cobra.Command)

RegisterNoColorFlag adds the persistent --no-color flag to root. The default is false so the flag's presence alone is the disable signal.

func ValidatePositiveLimit added in v1.71.1

func ValidatePositiveLimit(limit int) error

ValidatePositiveLimit returns an error if limit is less than 1. Use for --limit flags where 0 is not a documented "no-cap" value. For commands that explicitly document 0 as "no limit", skip this check.

Types

type BrowserLauncher

type BrowserLauncher interface {
	Browse(url string) error
}

type EditorLauncher

type EditorLauncher interface {
	Edit(filename string) error
}

type SystemBrowser

type SystemBrowser struct{}

func (*SystemBrowser) Browse

func (b *SystemBrowser) Browse(url string) error

Browse opens the given URL in the system browser.

type SystemEditor

type SystemEditor struct{}

func (*SystemEditor) Edit

func (e *SystemEditor) Edit(filename string) error

Edit opens the given filename in $EDITOR.

Jump to

Keyboard shortcuts

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