Documentation
¶
Overview ¶
Package app implements the core templr CLI commands and application logic.
Index ¶
- Constants
- Variables
- func ApplyConfigToLintOptions(opts *LintOptions, config *Config)
- func ApplyConfigToSharedOptions(opts *SharedOptions, config *Config)
- func Contains(s, substr string) bool
- func FindSchemaFile(configSchemaPath string) string
- func FormatSchemaErrors(result *SchemaValidationResult, mode string) string
- func GenerateSchema(data map[string]interface{}, config SchemaGenerateConfig) (map[string]interface{}, error)
- func GetVersion() string
- func RunDirMode(opts DirOptions) error
- func RunLegacyMode()
- func RunLintMode(opts LintOptions) error
- func RunRenderMode(opts RenderOptions) error
- func RunSchemaGenerate(opts SchemaOptions, config *Config) error
- func RunSchemaValidate(opts SchemaOptions, config *Config) error
- func RunWalkMode(opts WalkOptions) error
- type Config
- type DirOptions
- type FileInfo
- type FilesAPI
- func (f FilesAPI) AsBase64(path string) (string, error)
- func (f FilesAPI) AsDataURL(path, mimeType string) (string, error)
- func (f FilesAPI) AsHex(path string) (string, error)
- func (f FilesAPI) AsJSON(path string) (map[string]any, error)
- func (f FilesAPI) AsLines(path string) ([]string, error)
- func (f FilesAPI) AsYAML(path string) (map[string]any, error)
- func (f FilesAPI) Exists(path string) bool
- func (f FilesAPI) Get(path string) (string, error)
- func (f FilesAPI) GetBytes(path string) ([]byte, error)
- func (f FilesAPI) Glob(pat string) ([]string, error)
- func (f FilesAPI) GlobDetails(pat string) ([]FileInfo, error)
- func (f FilesAPI) Lines(path string) ([]string, error)
- func (f FilesAPI) ReadDir(path string) ([]string, error)
- func (f FilesAPI) Stat(path string) (FileInfo, error)
- type FilesConfig
- type LintConfig
- type LintIssue
- type LintOptions
- type LintResult
- type OutputConfig
- type RenderConfig
- type RenderOptions
- type SchemaConfig
- type SchemaError
- type SchemaGenerateConfig
- type SchemaOptions
- type SchemaValidationResult
- type SharedOptions
- type TemplateConfig
- type WalkOptions
Constants ¶
const ( ExitOK = 0 ExitGeneral = 1 ExitTemplateError = 2 ExitDataError = 3 ExitStrictError = 4 ExitGuardSkipped = 5 ExitLintWarn = 6 // lint found warnings (with --fail-on-warn) ExitLintError = 7 // lint found errors ExitSchemaError = 8 // schema validation failed )
Exit codes for CI-friendly behavior.
const (
// DefaultSchemaFile is the default schema filename to look for
DefaultSchemaFile = ".templr.schema.yml"
)
Variables ¶
var Version string
Version is set at build time via -ldflags
Functions ¶
func ApplyConfigToLintOptions ¶
func ApplyConfigToLintOptions(opts *LintOptions, config *Config)
ApplyConfigToLintOptions applies config values to LintOptions
func ApplyConfigToSharedOptions ¶
func ApplyConfigToSharedOptions(opts *SharedOptions, config *Config)
ApplyConfigToSharedOptions applies config values to SharedOptions CLI flags take precedence over config file values
func FindSchemaFile ¶
FindSchemaFile looks for schema file in order of precedence
func FormatSchemaErrors ¶
func FormatSchemaErrors(result *SchemaValidationResult, mode string) string
FormatSchemaErrors formats schema errors for display
func GenerateSchema ¶
func GenerateSchema(data map[string]interface{}, config SchemaGenerateConfig) (map[string]interface{}, error)
GenerateSchema generates a JSON Schema from data
func RunDirMode ¶
func RunDirMode(opts DirOptions) error
RunDirMode executes directory mode: parse all templates in dir, execute one entry
func RunLegacyMode ¶
func RunLegacyMode()
RunLegacyMode implements backward compatibility for the old flag-based CLI. This function parses flags in the old style and routes to the appropriate command.
func RunRenderMode ¶
func RunRenderMode(opts RenderOptions) error
RunRenderMode executes single-file render mode
func RunSchemaGenerate ¶
func RunSchemaGenerate(opts SchemaOptions, config *Config) error
RunSchemaGenerate generates a schema from data
func RunSchemaValidate ¶
func RunSchemaValidate(opts SchemaOptions, config *Config) error
RunSchemaValidate validates data against a schema
func RunWalkMode ¶
func RunWalkMode(opts WalkOptions) error
RunWalkMode executes walk mode: recursively render all templates in src to dst
Types ¶
type Config ¶
type Config struct {
Files FilesConfig `yaml:"files"`
Template TemplateConfig `yaml:"template"`
Schema SchemaConfig `yaml:"schema"`
Lint LintConfig `yaml:"lint"`
Render RenderConfig `yaml:"render"`
Output OutputConfig `yaml:"output"`
}
Config represents the complete configuration structure
func LoadConfig ¶
LoadConfig loads configuration from files with the following precedence: 1. Specified config file (--config flag) 2. .templr.yaml in current directory 3. ~/.config/templr/config.yaml (user config) 4. Built-in defaults
func NewDefaultConfig ¶
func NewDefaultConfig() *Config
NewDefaultConfig returns a Config with default values
type DirOptions ¶
DirOptions contains options specific to directory mode
type FilesAPI ¶
type FilesAPI struct {
Root string
}
FilesAPI provides a Helm-like .Files facade anchored at a directory.
func (FilesAPI) AsBase64 ¶
AsBase64 reads a file and returns its contents as a base64-encoded string.
func (FilesAPI) AsDataURL ¶
AsDataURL reads a file and returns it as a data URL (for embedding in HTML/CSS). If mimeType is empty, it will be auto-detected from the file extension.
func (FilesAPI) Glob ¶
Glob returns files matching the given glob pattern relative to the root directory.
func (FilesAPI) GlobDetails ¶
GlobDetails returns file metadata for all files matching the given pattern.
type FilesConfig ¶
type FilesConfig struct {
Extensions []string `yaml:"extensions"`
DefaultTemplatesDir string `yaml:"default_templates_dir"`
DefaultOutputDir string `yaml:"default_output_dir"`
DefaultValuesFile string `yaml:"default_values_file"`
Helpers []string `yaml:"helpers"`
}
FilesConfig contains file-related configuration
type LintConfig ¶
type LintConfig struct {
FailOnWarn bool `yaml:"fail_on_warn"`
FailOnUndefined bool `yaml:"fail_on_undefined"`
StrictMode bool `yaml:"strict_mode"`
OutputFormat string `yaml:"output_format"`
Exclude []string `yaml:"exclude"`
DisallowFunctions []string `yaml:"disallow_functions"`
RequiredVars []string `yaml:"required_vars"`
NoUndefCheck bool `yaml:"no_undefined_check"`
}
LintConfig contains linting configuration
type LintIssue ¶
type LintIssue struct {
Severity string // "error", "warn"
Category string // "parse", "undefined", "function", "guard"
File string // file path
Line int // line number (0 if unknown)
Column int // column number (0 if unknown)
Message string // human-readable message
}
LintIssue represents a single linting issue
type LintOptions ¶
type LintOptions struct {
In string // single file to lint
Dir string // directory to lint
Src string // source tree to walk and lint
FailOnWarn bool // exit with error on warnings
Format string // output format: text, json, github-actions
NoUndefCheck bool // skip undefined variable checking
Config *Config // configuration from file
}
LintOptions contains all configuration for lint mode
type LintResult ¶
LintResult contains the results of a lint operation
type OutputConfig ¶
type OutputConfig struct {
Color string `yaml:"color"` // auto, always, never
Verbose bool `yaml:"verbose"`
Quiet bool `yaml:"quiet"`
}
OutputConfig contains output formatting configuration
type RenderConfig ¶
type RenderConfig struct {
DryRun bool `yaml:"dry_run"`
InjectGuard bool `yaml:"inject_guard"`
GuardString string `yaml:"guard_string"`
PruneEmptyDirs bool `yaml:"prune_empty_dirs"`
}
RenderConfig contains rendering defaults
type RenderOptions ¶
RenderOptions contains options specific to single-file render mode
type SchemaConfig ¶
type SchemaConfig struct {
Path string `yaml:"path"` // Path to schema file (default: .templr.schema.yml)
Mode string `yaml:"mode"` // error|warn|strict (default: warn)
Generate SchemaGenerateConfig `yaml:"generate"` // Schema generation settings
}
SchemaConfig contains schema validation configuration
type SchemaError ¶
type SchemaError struct {
Path string // JSON path (e.g., ".service.replicas")
Message string // Error message
Value string // The actual value that failed
Suggestion string // Helpful suggestion for fixing
}
SchemaError represents a schema validation error
type SchemaGenerateConfig ¶
type SchemaGenerateConfig struct {
Required string `yaml:"required"` // all|none|auto (default: auto)
AdditionalProps bool `yaml:"additional_props"` // Allow additionalProperties (default: true)
InferTypes bool `yaml:"infer_types"` // Infer types from values (default: true)
}
SchemaGenerateConfig contains schema generation settings
type SchemaOptions ¶
type SchemaOptions struct {
SchemaPath string
Mode string
Output string
Required string
AdditionalProps bool
Format string
}
SchemaOptions contains options for schema commands
type SchemaValidationResult ¶
type SchemaValidationResult struct {
Errors []SchemaError
Warnings []SchemaError
Passed bool
}
SchemaValidationResult contains validation results
func ValidateWithSchema ¶
func ValidateWithSchema(data map[string]interface{}, schemaPath, mode string) (*SchemaValidationResult, error)
ValidateWithSchema validates data against a YAML schema file
type SharedOptions ¶
type SharedOptions struct {
}
SharedOptions contains flags common to all commands
type TemplateConfig ¶
type TemplateConfig struct {
LeftDelimiter string `yaml:"left_delimiter"`
RightDelimiter string `yaml:"right_delimiter"`
DefaultMissing string `yaml:"default_missing"`
}
TemplateConfig contains template engine configuration
type WalkOptions ¶
WalkOptions contains options specific to walk mode