Documentation
¶
Index ¶
- Constants
- func ApplyNoColorFlag(cmd *cobra.Command, ios *iostreams.IOStreams)
- func EnablePagerForAnnotated(root *cobra.Command, ios *iostreams.IOStreams)
- func ExplainError(ios *iostreams.IOStreams, err error)
- func FatalIfError(err error)
- func RegisterNoColorFlag(root *cobra.Command)
- type BrowserLauncher
- type EditorLauncher
- type SystemBrowser
- type SystemEditor
Constants ¶
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.
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
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
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 ExplainError ¶ added in v1.12.0
ExplainError writes a user-actionable message to ios.ErrOut.
This is now a thin shim over pkg/errfmt — kept only to avoid touching every caller in cmd/bitbottle. New presentation logic (codes, hints, TTY colour) lives in errfmt.Render; see that package for the full resolution order.
func FatalIfError ¶
func FatalIfError(err error)
func RegisterNoColorFlag ¶ added in v1.17.0
RegisterNoColorFlag adds the persistent --no-color flag to root. The default is false so the flag's presence alone is the disable signal.
Types ¶
type BrowserLauncher ¶
type EditorLauncher ¶
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.