cli

package
v1.0.0-rc.3 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2025 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package cli provides the command-line interface for make-help using Cobra.

This package handles argument parsing, flag validation, terminal detection, and delegates to the appropriate service packages for actual functionality. It is the only package that interacts with os.Args and stdout/stderr.

Commands

The CLI provides three commands:

  • make-help (default): Generate help output from Makefile documentation
  • make-help add-target: Add a help target to the Makefile
  • make-help remove-target: Remove help target artifacts

Color Detection

Color output is automatically enabled when stdout is a terminal. This can be overridden with --color (force on) or --no-color (force off). When output is piped, colors are disabled by default.

Configuration

The Config struct holds all CLI configuration and is passed to service packages. It includes both user-provided flags and derived state computed at runtime (e.g., UseColor).

Index

Constants

This section is empty.

Variables

View Source
var ErrLintWarningsFound = errors.New("lint warnings found")

ErrLintWarningsFound is a sentinel error returned when lint warnings are found. Cobra will translate this into exit code 1.

Functions

func HasAnyOptions

func HasAnyOptions() bool

HasAnyOptions checks if any command-line options were provided. It checks the os.Args for flags (excluding the program name).

func IsTerminal

func IsTerminal(fd uintptr) bool

IsTerminal returns true if the given file descriptor refers to a terminal.

func NewRootCmd

func NewRootCmd() *cobra.Command

NewRootCmd creates the root command for make-help. The default action is to run the help command.

func ParseCommandLineFromHelpFile

func ParseCommandLineFromHelpFile(cmdLine string, config *Config) error

ParseCommandLineFromHelpFile parses a command line string from a help.mk file and applies only allowed options to a Config. Only output/formatting, input, and verbose flags are allowed. Mode flags would cause an error.

func ResolveColorMode

func ResolveColorMode(config *Config) bool

ResolveColorMode determines whether to use colored output based on the config. It respects the ColorMode setting and checks if stdout is a terminal.

Types

type ColorMode

type ColorMode int

ColorMode represents the color output mode for the CLI.

const (
	// ColorAuto enables color output when connected to a terminal.
	ColorAuto ColorMode = iota

	// ColorAlways forces color output regardless of terminal detection.
	ColorAlways

	// ColorNever disables color output.
	ColorNever
)

func (ColorMode) String

func (c ColorMode) String() string

String returns the string representation of ColorMode.

type Config

type Config struct {

	// MakefilePath is the path to the main Makefile (resolved to absolute path).
	// If empty, defaults to "Makefile" in the current working directory.
	MakefilePath string

	// ColorMode determines when to use colored output.
	ColorMode ColorMode

	// Verbose enables verbose output for debugging file discovery and parsing.
	Verbose bool

	// KeepOrderCategories preserves category discovery order instead of alphabetical.
	KeepOrderCategories bool

	// KeepOrderTargets preserves target discovery order within categories.
	KeepOrderTargets bool

	// KeepOrderFiles preserves file discovery order instead of alphabetical.
	KeepOrderFiles bool

	// CategoryOrder specifies explicit category ordering.
	// Categories not in this list are appended alphabetically.
	CategoryOrder []string

	// DefaultCategory is the category name for uncategorized targets.
	// Required when mixing categorized and uncategorized targets.
	DefaultCategory string

	// HelpCategory is the category name for generated help targets (help, update-help).
	// Defaults to "Help" if not specified.
	HelpCategory string

	// HelpFileRelPath specifies a relative path for the generated help target file.
	// Must be a relative path (no leading '/'). If empty, location is determined automatically.
	HelpFileRelPath string

	// ShowHelp displays help dynamically instead of generating a help file.
	ShowHelp bool

	// RemoveHelpTarget indicates whether to remove help target from Makefile.
	RemoveHelpTarget bool

	// IncludeTargets lists undocumented targets to include in help.
	// Populated from --include-target flag (repeatable, comma-separated).
	IncludeTargets []string

	// IncludeAllPhony includes all .PHONY targets in help output.
	IncludeAllPhony bool

	// Target specifies a target name for detailed help view.
	Target string

	// DryRun shows what would be created/modified without actually making changes.
	// Valid with CreateHelpTarget or --lint --fix.
	DryRun bool

	// Lint enables lint mode to check documentation quality.
	Lint bool

	// Fix automatically fixes auto-fixable lint issues.
	// Only valid with --lint.
	Fix bool

	// UseColor is the resolved color setting based on ColorMode and terminal detection.
	UseColor bool

	// CommandLine stores the raw command line to be recorded in generated help files.
	// Captured from os.Args in PreRunE.
	CommandLine string
}

Config holds all CLI configuration options.

func NewConfig

func NewConfig() *Config

NewConfig creates a new Config with default values.

Jump to

Keyboard shortcuts

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