Documentation
¶
Overview ¶
Package enginecli provides common CLI bootstrapping functionality for forge commands.
This package eliminates duplicated main() function logic across 18+ command binaries by providing a unified bootstrap mechanism that handles:
- Version information initialization from ldflags
- Version flag handling (--version, -v, version)
- MCP server mode handling (--mcp flag)
- Standardized error handling and exit codes
Example usage:
package main
import (
"github.com/alexandremahdhaoui/forge/pkg/enginecli"
)
// Version information (set via ldflags)
var (
Version = "dev"
CommitSHA = "unknown"
BuildTimestamp = "unknown"
)
func main() {
enginecli.Bootstrap(enginecli.Config{
Name: "my-command",
Version: Version,
CommitSHA: CommitSHA,
BuildTimestamp: BuildTimestamp,
RunCLI: runCLI,
RunMCP: runMCP,
})
}
func runCLI() error {
// Command-specific CLI logic
return nil
}
func runMCP() error {
// Command-specific MCP server logic
return nil
}
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Bootstrap ¶
func Bootstrap(cfg Config)
Bootstrap provides a unified entry point for forge CLI commands. It handles version flags, MCP mode, and CLI execution with standardized error handling.
This function will call os.Exit and never return.
func BootstrapSimple ¶
BootstrapSimple is a convenience wrapper for commands that don't support MCP mode.
Types ¶
type Config ¶
type Config struct {
// Name is the command name (e.g., "go-build", "test-integration")
Name string
// Version information (typically set via ldflags)
Version string
CommitSHA string
BuildTimestamp string
// RunCLI is the function to execute in normal CLI mode
RunCLI func() error
// RunMCP is the function to execute in MCP server mode (optional)
// If nil, --mcp flag will result in an error
RunMCP func() error
// SuccessHandler is called when RunCLI completes successfully (optional)
// Defaults to no-op if not provided
SuccessHandler func()
// FailureHandler is called when RunCLI returns an error (optional)
// Receives the error and should print it appropriately
// Defaults to no-op if not provided
FailureHandler func(error)
// DocsConfig is the configuration for the docs subcommand (optional)
// If set and "docs" is the first argument, the docs command is handled internally
DocsConfig *enginedocs.Config
}
Config holds the configuration for CLI bootstrap.
Click to show internal directories.
Click to hide internal directories.