config

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: May 8, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package config manages the configuration for the contextvibes CLI application.

It defines the structure of the configuration, provides functions to load configuration from a YAML file (defaulting to '.contextvibes.yaml' in the project root), and offers a way to get default configuration values.

The primary components are:

  • Config: The main struct holding all configuration settings, including Git behavior, logging preferences, and validation rules for branch names and commit messages.
  • GitSettings, LoggingSettings, ValidationRule: Sub-structs organizing related configuration items.
  • GetDefaultConfig(): Returns a pointer to a Config struct populated with sensible default values.
  • LoadConfig(filePath string): Attempts to load configuration from the specified YAML file. Returns nil if the file doesn't exist, allowing graceful fallback to defaults.
  • FindRepoRootConfigPath(execClient *exec.ExecutorClient): Locates the configuration file by searching upwards from the current directory to the Git repository root.
  • MergeWithDefaults(loadedCfg *Config, defaultConfig *Config): Merges a loaded user configuration with the default configuration, giving precedence to user-defined values.

Constants are also defined for default filenames (e.g., DefaultConfigFileName, DefaultCodemodFilename, DefaultDescribeOutputFile, UltimateDefaultAILogFilename) and default patterns for validation. These constants are intended to be used by CLI commands to ensure consistent default behavior.

The typical flow involves: 1. Attempting to find and load a user-defined '.contextvibes.yaml' file. 2. If found and valid, merging it with the application's default configuration. 3. If not found or invalid, using the application's default configuration directly. The resulting configuration is then used throughout the application, particularly by the cmd package to influence command behavior.

Index

Constants

View Source
const (
	// DefaultConfigFileName is the default name for the contextvibes configuration file.
	DefaultConfigFileName = ".contextvibes.yaml"

	// DefaultCodemodFilename is the default name for the codemod script JSON file.
	// To align with README and cmd/codemod.go, this should be "codemod.json"
	// For now, keeping as per your existing file to focus on the commit regex.
	// DefaultCodemodFilename = "contextvibes-codemod.json" // Previous value
	DefaultCodemodFilename = "codemod.json" // Aligning with cmd/codemod.go and README

	// DefaultDescribeOutputFile is the default name for the file generated by 'describe' and 'diff'.
	DefaultDescribeOutputFile = "contextvibes.md"

	// DefaultBranchNamePattern is the default regex for validating branch names.
	DefaultBranchNamePattern = `^((feature|fix|docs|format)/.+)$`

	// DefaultCommitMessagePattern is the default regex for validating commit messages.
	// MODIFIED HERE TO ALLOW '/' IN SCOPE
	DefaultCommitMessagePattern = `^(BREAKING|feat|fix|docs|style|refactor|perf|test|build|ci|chore|revert)(\([a-zA-Z0-9\-_/]+\))?:\s.+`

	// DefaultGitRemote is the default Git remote name.
	DefaultGitRemote = "origin"
	// DefaultGitMainBranch is the default Git main branch name.
	DefaultGitMainBranch = "main"
	// UltimateDefaultAILogFilename is the fallback name for the AI trace log file.
	// To align with README and common usage: "contextvibes_ai_trace.log"
	// For now, keeping as per your existing file to focus on the commit regex.
	// UltimateDefaultAILogFilename = "contextvibes.log" // Previous value
	UltimateDefaultAILogFilename = "contextvibes_ai_trace.log" // Aligning with README

)

Variables

This section is empty.

Functions

func FindRepoRootConfigPath

func FindRepoRootConfigPath(execClient *exec.ExecutorClient) (string, error)

FindRepoRootConfigPath now takes an ExecutorClient to find the repo root.

Types

type Config

type Config struct {
	Git        GitSettings     `yaml:"git,omitempty"`
	Logging    LoggingSettings `yaml:"logging,omitempty"`
	Validation struct {
		BranchName    ValidationRule `yaml:"branchName,omitempty"`
		CommitMessage ValidationRule `yaml:"commitMessage,omitempty"`
	} `yaml:"validation,omitempty"`
}

func GetDefaultConfig

func GetDefaultConfig() *Config

func LoadConfig

func LoadConfig(filePath string) (*Config, error)

func MergeWithDefaults

func MergeWithDefaults(loadedCfg *Config, defaultConfig *Config) *Config

type GitSettings

type GitSettings struct {
	DefaultRemote     string `yaml:"defaultRemote,omitempty"`
	DefaultMainBranch string `yaml:"defaultMainBranch,omitempty"`
}

type LoggingSettings

type LoggingSettings struct {
	DefaultAILogFile string `yaml:"defaultAILogFile,omitempty"`
}

type ValidationRule

type ValidationRule struct {
	Enable  *bool  `yaml:"enable,omitempty"` // Pointer to bool to distinguish between false and not set
	Pattern string `yaml:"pattern,omitempty"`
}

Jump to

Keyboard shortcuts

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