common

package module
v0.8.23 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: Apache-2.0 Imports: 3 Imported by: 1 module, 1 package

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 common holds tiny CLI utilities shared across mcpkit's single-purpose binaries (cmd/mcpskills today; cmd/mcpkit-auth and friends as they appear). Scope is deliberately narrow: env-var precedence helpers, TTY detection, and color helpers. Domain surfaces (mcpkit/client wrapper construction, server registration, etc.) live in the binaries themselves.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ColorEnabled

func ColorEnabled(mode ColorMode, w io.Writer) bool

ColorEnabled reports whether w should receive ANSI color escapes under the given mode. ColorAuto checks whether w is a *os.File pointing at a TTY; non-file writers default to no color.

func LookupURL

func LookupURL(flagValue, envVar, defaultURL string) string

LookupURL returns the URL to target for a CLI invocation. Precedence (highest first):

  1. flag value (passed in by the caller after cobra's flag parsing)
  2. $<envVar> if set and non-empty
  3. defaultURL

Used by inspect-style subcommands that need a server URL with the usual flag-then-env-then-default pattern. Callers wire the flag.

Types

type ColorMode

type ColorMode int

ColorMode controls whether ANSI color escapes appear in output.

const (
	// ColorAuto enables color when stdout is a TTY, disables it when
	// piped. Standard CLI behavior.
	ColorAuto ColorMode = iota
	// ColorAlways forces color on. Useful when the caller pipes into a
	// terminal-aware pager (e.g. less -R).
	ColorAlways
	// ColorNever disables color unconditionally. Used by --no-color and
	// for capture-and-diff tests.
	ColorNever
)

type Painter

type Painter struct {
	// contains filtered or unexported fields
}

Painter wraps ANSI escape application so callers can write

fmt.Fprintln(out, p.Green("✓"), "git-workflow", p.Dim("(verified)"))

without sprinkling escape strings through the call sites. When color is disabled the methods return the input unchanged.

func NewPainter

func NewPainter(mode ColorMode, w io.Writer) *Painter

NewPainter constructs a Painter for w under the given mode.

func (*Painter) Bold

func (p *Painter) Bold(s string) string

Bold renders s in ANSI bold.

func (*Painter) Cyan

func (p *Painter) Cyan(s string) string

Cyan renders s in ANSI cyan (informational headers).

func (*Painter) Dim

func (p *Painter) Dim(s string) string

Dim renders s in ANSI dim (de-emphasized rows).

func (*Painter) Green

func (p *Painter) Green(s string) string

Green renders s in ANSI green (success).

func (*Painter) Red

func (p *Painter) Red(s string) string

Red renders s in ANSI red (failure).

Jump to

Keyboard shortcuts

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