Documentation
¶
Overview ¶
Package cli provides automation and integration support for the CLI
Package cli provides comprehensive command-line interface functionality for the Open Source Project Generator.
This package handles comprehensive CLI operations including:
- Advanced project generation with multiple options
- Project validation and auditing
- Template management and discovery
- Configuration management
- Version and update management
- Cache management
- Logging and debugging support
Package cli provides configuration management commands for the CLI generator.
This file implements CLI commands for managing saved configurations including listing, viewing, saving, loading, and deleting configurations.
Package cli provides error handling and exit code management for automation ¶
Package cli provides interactive flow management for the CLI generator.
This file implements the InteractiveFlowManager that orchestrates the complete interactive project generation workflow including template selection, configuration collection, directory selection, preview generation, and confirmation.
Package cli provides integration for interactive directory selection in the CLI.
This file integrates the directory selection functionality into the existing CLI generate command workflow.
Index ¶
- Constants
- func NewCLI(configManager interfaces.ConfigManager, validator interfaces.ValidationEngine, ...) interfaces.CLIInterface
- func NewVersionCommand(cli interfaces.CLIInterface) *cobra.Command
- func RunVersionCommand(cmd *cobra.Command, args []string, cli interfaces.CLIInterface) error
- type CIEnvironment
- type CLI
- func (c *CLI) AuditProject(path string, options interfaces.AuditOptions) (*interfaces.AuditResult, error)
- func (c *CLI) AuditProjectAdvanced(path string, options *interfaces.AuditOptions) (*interfaces.AuditResult, error)
- func (c *CLI) CheckCompatibility(projectPath string) (*interfaces.CompatibilityResult, error)
- func (c *CLI) CheckUpdates() (*interfaces.UpdateInfo, error)
- func (c *CLI) CleanCache() error
- func (c *CLI) ClearCache() error
- func (c *CLI) ConfirmAdvancedGeneration(config *models.ProjectConfig, options *interfaces.AdvancedOptions) bool
- func (c *CLI) ConfirmGeneration(config *models.ProjectConfig) bool
- func (c *CLI) DebugOutput(format string, args ...interface{})
- func (c *CLI) DisableOfflineMode() error
- func (c *CLI) EditConfig() error
- func (c *CLI) EnableOfflineMode() error
- func (c *CLI) ErrorOutput(format string, args ...interface{})
- func (c *CLI) ExportConfig(path string) error
- func (c *CLI) FinishOperationWithError(ctx *interfaces.OperationContext, operation string, err error)
- func (c *CLI) FinishOperationWithOutput(ctx *interfaces.OperationContext, operation string, description string)
- func (c *CLI) GenerateFromConfig(configPath string, options interfaces.GenerateOptions) error
- func (c *CLI) GenerateReport(reportType string, format string, outputFile string) error
- func (c *CLI) GenerateWithAdvancedOptions(config *models.ProjectConfig, options *interfaces.AdvancedOptions) error
- func (c *CLI) GetCacheStats() (*interfaces.CacheStats, error)
- func (c *CLI) GetConfigurationSources() ([]interfaces.ConfigSource, error)
- func (c *CLI) GetExitCode() int
- func (c *CLI) GetLatestPackageVersions() (map[string]string, error)
- func (c *CLI) GetLogFileLocations() ([]string, error)
- func (c *CLI) GetLogLevel() string
- func (c *CLI) GetPackageVersions() (map[string]string, error)
- func (c *CLI) GetTemplateDependencies(name string) ([]string, error)
- func (c *CLI) GetTemplateInfo(name string) (*interfaces.TemplateInfo, error)
- func (c *CLI) GetTemplateMetadata(name string) (*interfaces.TemplateMetadata, error)
- func (c *CLI) GetVersionManager() interfaces.VersionManager
- func (c *CLI) InstallUpdates() error
- func (c *CLI) ListTemplates(filter interfaces.TemplateFilter) ([]interfaces.TemplateInfo, error)
- func (c *CLI) LoadConfigFromFile(path string) error
- func (c *CLI) LoadConfiguration(sources []string) (*models.ProjectConfig, error)
- func (c *CLI) MergeConfigurations(configs []*models.ProjectConfig) (*models.ProjectConfig, error)
- func (c *CLI) PerformanceOutput(operation string, duration time.Duration, metrics map[string]interface{})
- func (c *CLI) PromptAdvancedOptions() (*interfaces.AdvancedOptions, error)
- func (c *CLI) PromptProjectDetails() (*models.ProjectConfig, error)
- func (c *CLI) QuietOutput(format string, args ...interface{})
- func (c *CLI) RepairCache() error
- func (c *CLI) Run(args []string) error
- func (c *CLI) RunNonInteractive(config *models.ProjectConfig, options *interfaces.AdvancedOptions) error
- func (c *CLI) SearchTemplates(query string) ([]interfaces.TemplateInfo, error)
- func (c *CLI) SelectTemplateInteractively(filter interfaces.TemplateFilter) (*interfaces.TemplateInfo, error)
- func (c *CLI) SetConfig(key, value string) error
- func (c *CLI) SetExitCode(code int)
- func (c *CLI) SetLogLevel(level string) error
- func (c *CLI) ShowCache() error
- func (c *CLI) ShowConfig() error
- func (c *CLI) ShowLogs() error
- func (c *CLI) ShowRecentLogs(lines int, level string) error
- func (c *CLI) ShowVersion(options interfaces.VersionOptions) error
- func (c *CLI) StartOperationWithOutput(operation string, description string) *interfaces.OperationContext
- func (c *CLI) SuccessOutput(format string, args ...interface{})
- func (c *CLI) ValidateCache() error
- func (c *CLI) ValidateConfig() error
- func (c *CLI) ValidateConfigurationSchema(config *models.ProjectConfig) error
- func (c *CLI) ValidateCustomTemplate(path string) (*interfaces.TemplateValidationResult, error)
- func (c *CLI) ValidateProject(path string, options interfaces.ValidationOptions) (*interfaces.ValidationResult, error)
- func (c *CLI) ValidateProjectAdvanced(path string, options *interfaces.ValidationOptions) (*interfaces.ValidationResult, error)
- func (c *CLI) ValidateTemplate(path string) (*interfaces.TemplateValidationResult, error)
- func (c *CLI) VerboseOutput(format string, args ...interface{})
- func (c *CLI) WarningOutput(format string, args ...interface{})
- type CLIError
- type EnvironmentConfig
- type ErrorContext
- type InteractiveFlowManager
- type StructuredError
- func (e *StructuredError) Error() string
- func (e *StructuredError) ExitCode() int
- func (e *StructuredError) ToJSON() ([]byte, error)
- func (e *StructuredError) WithContext(ctx *ErrorContext) *StructuredError
- func (e *StructuredError) WithDetails(key string, value interface{}) *StructuredError
- func (e *StructuredError) WithSuggestions(suggestions ...string) *StructuredError
- type SuccessContext
- type SuccessResponse
Constants ¶
const ( ColorReset = "\033[0m" ColorRed = "\033[31m" ColorGreen = "\033[32m" ColorYellow = "\033[33m" ColorBlue = "\033[34m" ColorPurple = "\033[35m" ColorCyan = "\033[36m" ColorWhite = "\033[37m" ColorBold = "\033[1m" ColorDim = "\033[2m" )
Color constants for beautiful CLI output
const ( ExitCodeSuccess = 0 ExitCodeGeneral = 1 ExitCodeValidationFailed = 2 ExitCodeConfigurationInvalid = 3 ExitCodeTemplateNotFound = 4 ExitCodeNetworkError = 5 ExitCodeFileSystemError = 6 ExitCodePermissionDenied = 7 ExitCodeCacheError = 8 ExitCodeVersionError = 9 ExitCodeAuditFailed = 10 ExitCodeGenerationFailed = 11 ExitCodeInternalError = 99 )
Exit code constants for different error types
const ( ErrorTypeValidation = "validation" ErrorTypeConfiguration = "configuration" ErrorTypeTemplate = "template" ErrorTypeNetwork = "network" ErrorTypeFileSystem = "filesystem" ErrorTypePermission = "permission" ErrorTypeCache = "cache" ErrorTypeVersion = "version" ErrorTypeAudit = "audit" ErrorTypeGeneration = "generation" ErrorTypeInternal = "internal" )
Error type constants
Variables ¶
This section is empty.
Functions ¶
func NewCLI ¶
func NewCLI( configManager interfaces.ConfigManager, validator interfaces.ValidationEngine, templateManager interfaces.TemplateManager, cacheManager interfaces.CacheManager, versionManager interfaces.VersionManager, auditEngine interfaces.AuditEngine, logger interfaces.Logger, version string, ) interfaces.CLIInterface
NewCLI creates a new CLI instance with all required dependencies.
Parameters:
- configManager: Handles configuration loading and validation
- validator: Provides input and project validation
- templateManager: Manages template operations
- cacheManager: Handles caching and offline mode
- versionManager: Manages version information and updates
- auditEngine: Provides auditing capabilities
- logger: Provides logging functionality
- version: Generator version string
Returns:
- interfaces.CLIInterface: New CLI instance ready for use
func NewVersionCommand ¶
func NewVersionCommand(cli interfaces.CLIInterface) *cobra.Command
NewVersionCommand creates a new version command
func RunVersionCommand ¶
func RunVersionCommand(cmd *cobra.Command, args []string, cli interfaces.CLIInterface) error
RunVersionCommand displays the current version of the generator
Types ¶
type CIEnvironment ¶
type CIEnvironment struct {
IsCI bool `json:"is_ci"`
Provider string `json:"provider"`
BuildID string `json:"build_id,omitempty"`
BuildNumber string `json:"build_number,omitempty"`
Branch string `json:"branch,omitempty"`
Commit string `json:"commit,omitempty"`
Repository string `json:"repository,omitempty"`
PullRequest string `json:"pull_request,omitempty"`
JobID string `json:"job_id,omitempty"`
WorkflowID string `json:"workflow_id,omitempty"`
Environment string `json:"environment,omitempty"`
Actor string `json:"actor,omitempty"`
}
CIEnvironment represents detected CI/CD environment information
type CLI ¶
type CLI struct {
// contains filtered or unexported fields
}
CLI implements the CLIInterface for comprehensive CLI operations.
The CLI struct provides methods for:
- All documented CLI commands and flags
- Advanced project generation options
- Template management and validation
- Configuration management
- Auditing and validation capabilities
- Cache and offline mode support
- Interactive UI for guided project generation
func (*CLI) AuditProject ¶
func (c *CLI) AuditProject(path string, options interfaces.AuditOptions) (*interfaces.AuditResult, error)
func (*CLI) AuditProjectAdvanced ¶
func (c *CLI) AuditProjectAdvanced(path string, options *interfaces.AuditOptions) (*interfaces.AuditResult, error)
func (*CLI) CheckCompatibility ¶
func (c *CLI) CheckCompatibility(projectPath string) (*interfaces.CompatibilityResult, error)
func (*CLI) CheckUpdates ¶
func (c *CLI) CheckUpdates() (*interfaces.UpdateInfo, error)
func (*CLI) CleanCache ¶
func (*CLI) ClearCache ¶
func (*CLI) ConfirmAdvancedGeneration ¶
func (c *CLI) ConfirmAdvancedGeneration(config *models.ProjectConfig, options *interfaces.AdvancedOptions) bool
func (*CLI) ConfirmGeneration ¶
func (c *CLI) ConfirmGeneration(config *models.ProjectConfig) bool
ConfirmGeneration shows a basic configuration preview and asks for user confirmation.
func (*CLI) DebugOutput ¶
DebugOutput prints debug information if debug mode is enabled
func (*CLI) DisableOfflineMode ¶
func (*CLI) EditConfig ¶
func (*CLI) EnableOfflineMode ¶
func (*CLI) ErrorOutput ¶
ErrorOutput prints error information (always shown unless completely silent)
func (*CLI) ExportConfig ¶
func (*CLI) FinishOperationWithError ¶
func (c *CLI) FinishOperationWithError(ctx *interfaces.OperationContext, operation string, err error)
FinishOperationWithError completes an operation with error output
func (*CLI) FinishOperationWithOutput ¶
func (c *CLI) FinishOperationWithOutput(ctx *interfaces.OperationContext, operation string, description string)
FinishOperationWithOutput completes an operation with verbose output
func (*CLI) GenerateFromConfig ¶
func (c *CLI) GenerateFromConfig(configPath string, options interfaces.GenerateOptions) error
func (*CLI) GenerateReport ¶
func (*CLI) GenerateWithAdvancedOptions ¶
func (c *CLI) GenerateWithAdvancedOptions(config *models.ProjectConfig, options *interfaces.AdvancedOptions) error
func (*CLI) GetCacheStats ¶
func (c *CLI) GetCacheStats() (*interfaces.CacheStats, error)
func (*CLI) GetConfigurationSources ¶
func (c *CLI) GetConfigurationSources() ([]interfaces.ConfigSource, error)
func (*CLI) GetLatestPackageVersions ¶
func (*CLI) GetLogFileLocations ¶
func (*CLI) GetLogLevel ¶
func (*CLI) GetTemplateDependencies ¶
func (*CLI) GetTemplateInfo ¶
func (c *CLI) GetTemplateInfo(name string) (*interfaces.TemplateInfo, error)
func (*CLI) GetTemplateMetadata ¶
func (c *CLI) GetTemplateMetadata(name string) (*interfaces.TemplateMetadata, error)
func (*CLI) GetVersionManager ¶
func (c *CLI) GetVersionManager() interfaces.VersionManager
GetVersionManager returns the version manager instance
func (*CLI) InstallUpdates ¶
func (*CLI) ListTemplates ¶
func (c *CLI) ListTemplates(filter interfaces.TemplateFilter) ([]interfaces.TemplateInfo, error)
func (*CLI) LoadConfigFromFile ¶
LoadConfigFromFile loads configuration from a file
func (*CLI) LoadConfiguration ¶
func (c *CLI) LoadConfiguration(sources []string) (*models.ProjectConfig, error)
func (*CLI) MergeConfigurations ¶
func (c *CLI) MergeConfigurations(configs []*models.ProjectConfig) (*models.ProjectConfig, error)
func (*CLI) PerformanceOutput ¶
func (c *CLI) PerformanceOutput(operation string, duration time.Duration, metrics map[string]interface{})
PerformanceOutput prints performance metrics if debug mode is enabled
func (*CLI) PromptAdvancedOptions ¶
func (c *CLI) PromptAdvancedOptions() (*interfaces.AdvancedOptions, error)
func (*CLI) PromptProjectDetails ¶
func (c *CLI) PromptProjectDetails() (*models.ProjectConfig, error)
PromptProjectDetails collects basic project configuration from user input.
func (*CLI) QuietOutput ¶
QuietOutput prints information only if not in quiet mode
func (*CLI) RepairCache ¶
func (*CLI) RunNonInteractive ¶
func (c *CLI) RunNonInteractive(config *models.ProjectConfig, options *interfaces.AdvancedOptions) error
func (*CLI) SearchTemplates ¶
func (c *CLI) SearchTemplates(query string) ([]interfaces.TemplateInfo, error)
func (*CLI) SelectTemplateInteractively ¶
func (c *CLI) SelectTemplateInteractively(filter interfaces.TemplateFilter) (*interfaces.TemplateInfo, error)
func (*CLI) SetExitCode ¶
SetExitCode sets the exit code for the CLI
func (*CLI) SetLogLevel ¶
func (*CLI) ShowConfig ¶
func (*CLI) ShowVersion ¶
func (c *CLI) ShowVersion(options interfaces.VersionOptions) error
func (*CLI) StartOperationWithOutput ¶
func (c *CLI) StartOperationWithOutput(operation string, description string) *interfaces.OperationContext
StartOperationWithOutput starts an operation with verbose output
func (*CLI) SuccessOutput ¶
SuccessOutput prints success information if not in quiet mode
func (*CLI) ValidateCache ¶
func (*CLI) ValidateConfig ¶
func (*CLI) ValidateConfigurationSchema ¶
func (c *CLI) ValidateConfigurationSchema(config *models.ProjectConfig) error
func (*CLI) ValidateCustomTemplate ¶
func (c *CLI) ValidateCustomTemplate(path string) (*interfaces.TemplateValidationResult, error)
func (*CLI) ValidateProject ¶
func (c *CLI) ValidateProject(path string, options interfaces.ValidationOptions) (*interfaces.ValidationResult, error)
func (*CLI) ValidateProjectAdvanced ¶
func (c *CLI) ValidateProjectAdvanced(path string, options *interfaces.ValidationOptions) (*interfaces.ValidationResult, error)
func (*CLI) ValidateTemplate ¶
func (c *CLI) ValidateTemplate(path string) (*interfaces.TemplateValidationResult, error)
func (*CLI) VerboseOutput ¶
VerboseOutput prints verbose information if verbose mode is enabled
func (*CLI) WarningOutput ¶
WarningOutput prints warning information if not in quiet mode
type CLIError ¶
CLIError represents a CLI error with exit code information
func NewCLIError ¶
NewCLIError creates a new CLI error with the specified message and exit code
type EnvironmentConfig ¶
type EnvironmentConfig struct {
// Project configuration
ProjectName string `env:"GENERATOR_PROJECT_NAME"`
ProjectOrganization string `env:"GENERATOR_PROJECT_ORGANIZATION"`
ProjectDescription string `env:"GENERATOR_PROJECT_DESCRIPTION"`
ProjectLicense string `env:"GENERATOR_PROJECT_LICENSE"`
OutputPath string `env:"GENERATOR_OUTPUT_PATH"`
// Generation options
Force bool `env:"GENERATOR_FORCE"`
Minimal bool `env:"GENERATOR_MINIMAL"`
Offline bool `env:"GENERATOR_OFFLINE"`
UpdateVersions bool `env:"GENERATOR_UPDATE_VERSIONS"`
SkipValidation bool `env:"GENERATOR_SKIP_VALIDATION"`
BackupExisting bool `env:"GENERATOR_BACKUP_EXISTING"`
IncludeExamples bool `env:"GENERATOR_INCLUDE_EXAMPLES"`
Template string `env:"GENERATOR_TEMPLATE"`
// Component selection
Frontend bool `env:"GENERATOR_FRONTEND"`
Backend bool `env:"GENERATOR_BACKEND"`
Mobile bool `env:"GENERATOR_MOBILE"`
Infrastructure bool `env:"GENERATOR_INFRASTRUCTURE"`
// Technology selection
FrontendTech string `env:"GENERATOR_FRONTEND_TECH"`
BackendTech string `env:"GENERATOR_BACKEND_TECH"`
MobileTech string `env:"GENERATOR_MOBILE_TECH"`
InfrastructureTech string `env:"GENERATOR_INFRASTRUCTURE_TECH"`
// CLI behavior
NonInteractive bool `env:"GENERATOR_NON_INTERACTIVE"`
OutputFormat string `env:"GENERATOR_OUTPUT_FORMAT"`
LogLevel string `env:"GENERATOR_LOG_LEVEL"`
Verbose bool `env:"GENERATOR_VERBOSE"`
Quiet bool `env:"GENERATOR_QUIET"`
}
EnvironmentConfig holds configuration loaded from environment variables
type ErrorContext ¶
type ErrorContext struct {
Command string `json:"command"`
Arguments []string `json:"arguments"`
Flags map[string]string `json:"flags"`
WorkingDir string `json:"working_dir"`
Environment string `json:"environment,omitempty"`
CI *CIEnvironment `json:"ci,omitempty"`
}
ErrorContext provides context information for structured errors
type InteractiveFlowManager ¶
type InteractiveFlowManager struct {
// contains filtered or unexported fields
}
InteractiveFlowManager orchestrates the complete interactive generation workflow
func NewInteractiveFlowManager ¶
func NewInteractiveFlowManager( cli *CLI, templateManager interfaces.TemplateManager, configManager interfaces.ConfigManager, validator interfaces.ValidationEngine, logger interfaces.Logger, ui interfaces.InteractiveUIInterface, ) *InteractiveFlowManager
NewInteractiveFlowManager creates a new interactive flow manager
func (*InteractiveFlowManager) RunInteractiveFlow ¶
func (ifm *InteractiveFlowManager) RunInteractiveFlow(ctx context.Context, options interfaces.GenerateOptions) error
RunInteractiveFlow executes the complete interactive generation workflow
type StructuredError ¶
type StructuredError struct {
Type string `json:"type"`
Code int `json:"code"`
Message string `json:"message"`
Details map[string]interface{} `json:"details,omitempty"`
Suggestions []string `json:"suggestions,omitempty"`
Context *ErrorContext `json:"context,omitempty"`
Timestamp time.Time `json:"timestamp"`
}
StructuredError represents an error with structured information for automation
func NewStructuredError ¶
func NewStructuredError(errorType, message string, code int) *StructuredError
NewStructuredError creates a new structured error
func (*StructuredError) Error ¶
func (e *StructuredError) Error() string
Error implements the error interface
func (*StructuredError) ExitCode ¶
func (e *StructuredError) ExitCode() int
ExitCode returns the appropriate exit code for the error
func (*StructuredError) ToJSON ¶
func (e *StructuredError) ToJSON() ([]byte, error)
ToJSON converts the error to JSON format
func (*StructuredError) WithContext ¶
func (e *StructuredError) WithContext(ctx *ErrorContext) *StructuredError
WithContext adds context to the structured error
func (*StructuredError) WithDetails ¶
func (e *StructuredError) WithDetails(key string, value interface{}) *StructuredError
WithDetails adds details to the structured error
func (*StructuredError) WithSuggestions ¶
func (e *StructuredError) WithSuggestions(suggestions ...string) *StructuredError
WithSuggestions adds suggestions to the structured error
type SuccessContext ¶
type SuccessContext struct {
Command string `json:"command"`
Arguments []string `json:"arguments"`
Duration string `json:"duration,omitempty"`
CI *CIEnvironment `json:"ci,omitempty"`
}
SuccessContext provides context for successful operations
type SuccessResponse ¶
type SuccessResponse struct {
Success bool `json:"success"`
Message string `json:"message,omitempty"`
Data interface{} `json:"data,omitempty"`
Timestamp time.Time `json:"timestamp"`
Context *SuccessContext `json:"context,omitempty"`
}
Success response structure for machine-readable output