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 ¶
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 ¶
IsTerminal returns true if the given file descriptor refers to a terminal.
func NewRootCmd ¶
NewRootCmd creates the root command for make-help. The default action is to run the help command.
func ParseCommandLineFromHelpFile ¶
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 ¶
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 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.