config

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2026 License: MIT Imports: 12 Imported by: 0

README

Configuration Settings

The Tech Stack Analyzer supports configuration through command-line flags and environment variables.

Settings Structure

type Settings struct {
    // Output settings
    OutputFile  string
    PrettyPrint bool

    // Scan behavior
    ExcludePatterns []string
    Aggregate       string

    // Logging
    LogLevel logrus.Level
    LogFormat string // "text" or "json"
}

Command Line Flags

Flag Environment Variable Default Description
--output, -o STACK_ANALYZER_OUTPUT stdout Output file path
--pretty STACK_ANALYZER_PRETTY true Pretty print JSON output
--exclude-dir STACK_ANALYZER_EXCLUDE_DIRS (none) Comma-separated directories to exclude
--aggregate STACK_ANALYZER_AGGREGATE (none) Aggregate fields to include
--log-level STACK_ANALYZER_LOG_LEVEL error Log level: trace, debug, error, fatal
--log-format STACK_ANALYZER_LOG_FORMAT text Log format: text or json

Examples

Using Environment Variables
export STACK_ANALYZER_PRETTY=false
export STACK_ANALYZER_EXCLUDE_DIRS=vendor,node_modules,build
export STACK_ANALYZER_OUTPUT=/tmp/scan-results.json
export STACK_ANALYZER_LOG_LEVEL=debug
export STACK_ANALYZER_LOG_FORMAT=json

./bin/stack-analyzer scan /path/to/project
Mixing Flags and Environment Variables
export STACK_ANALYZER_EXCLUDE_DIRS=vendor,node_modules
export STACK_ANALYZER_LOG_LEVEL=trace

./bin/stack-analyzer scan /path/to/project --pretty --output results.json
Command Line Only
./bin/stack-analyzer scan /path/to/project \
  --exclude-dir vendor,node_modules,build \
  --log-level debug \
  --log-format json \
  --output results.json
Logging Examples
# Debug logging with structured fields
./bin/stack-analyzer scan /path/to/project --log-level debug

# JSON logging for automated processing
./bin/stack-analyzer scan /path/to/project --log-format json

# Trace level for maximum detail
./bin/stack-analyzer scan /path/to/project --log-level trace

# Environment variables for logging
STACK_ANALYZER_LOG_LEVEL=debug STACK_ANALYZER_LOG_FORMAT=json \
  ./bin/stack-analyzer scan /path/to/project

Precedence

  1. Command line flags take highest precedence
  2. Environment variables are used as defaults
  3. Built-in defaults are used when neither is provided

Implementation Notes

  • Settings are initialized once during command startup
  • Environment variables are loaded automatically
  • Settings validation happens before scanning begins
  • The settings object is passed to scanner initialization

Future Enhancements

  • Profile-based settings
  • Global user configuration in ~/.config/stack-analyzer/

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadCategoriesConfig

func LoadCategoriesConfig() (*types.CategoriesConfig, error)

LoadCategoriesConfig loads the categories configuration from categories.yaml

Types

type ConfigTech

type ConfigTech struct {
	Tech   string `yaml:"tech"`
	Reason string `yaml:"reason,omitempty"`
}

ConfigTech represents a technology to add to the scan

type ScanConfig

type ScanConfig struct {
	Properties map[string]interface{} `yaml:"properties,omitempty"`
	Exclude    []string               `yaml:"exclude,omitempty"`
	Techs      []ConfigTech           `yaml:"techs,omitempty"`
	RootID     string                 `yaml:"root_id,omitempty"` // Override random root ID for deterministic scans
}

ScanConfig represents the .stack-analyzer.yml configuration file

func LoadConfig

func LoadConfig(scanPath string) (*ScanConfig, error)

LoadConfig attempts to load .stack-analyzer.yml from the scan root Returns nil if file doesn't exist (not an error)

func (*ScanConfig) MergeExcludes

func (c *ScanConfig) MergeExcludes(cliExcludes []string) []string

MergeExcludes merges config excludes with CLI excludes CLI excludes take precedence

type ScanConfigFile

type ScanConfigFile struct {
	// Root-level metadata (consistent with .stack-analyzer.yml)
	Properties map[string]interface{} `yaml:"properties,omitempty" json:"properties,omitempty"`

	// Root-level excludes (consistent with .stack-analyzer.yml)
	Exclude []string `yaml:"exclude,omitempty" json:"exclude,omitempty"`

	// Root-level additional technologies (consistent with .stack-analyzer.yml)
	Techs []ConfigTech `yaml:"techs,omitempty" json:"techs,omitempty"`

	// Scan section with flat CLI options (matching CLI arguments)
	Scan ScanOptions `yaml:"scan,omitempty" json:"scan,omitempty"`
}

ScanConfigFile represents the external scan configuration file

func LoadScanConfig

func LoadScanConfig(configPath string) (*ScanConfigFile, error)

LoadScanConfig loads scan configuration from file path or inline JSON

func (*ScanConfigFile) GetMergedConfig

func (c *ScanConfigFile) GetMergedConfig(projectConfig *ScanConfig) *ScanConfig

GetMergedConfig merges scan config with project config (.stack-analyzer.yml) Returns a combined config for the scan operation

func (*ScanConfigFile) MergeWithSettings

func (c *ScanConfigFile) MergeWithSettings(settings *Settings)

MergeWithSettings merges scan config with existing settings CLI flags take precedence over config file settings

type ScanOptions

type ScanOptions struct {
	// Output settings
	OutputFile  string `yaml:"output_file,omitempty" json:"output_file,omitempty" default:"stack-analysis.json"`
	PrettyPrint bool   `yaml:"pretty,omitempty" json:"pretty,omitempty" default:"true"`
	Aggregate   string `yaml:"aggregate,omitempty" json:"aggregate,omitempty" default:""`

	// Scan behavior
	ExcludePatterns          []string `yaml:"exclude_patterns,omitempty" json:"exclude_patterns,omitempty"`
	Verbose                  bool     `yaml:"verbose,omitempty" json:"verbose,omitempty" default:"false"`
	Debug                    bool     `yaml:"debug,omitempty" json:"debug,omitempty" default:"false"`
	TraceTimings             bool     `yaml:"trace_timings,omitempty" json:"trace_timings,omitempty" default:"false"`
	TraceRules               bool     `yaml:"trace_rules,omitempty" json:"trace_rules,omitempty" default:"false"`
	FilterRules              []string `yaml:"filter_rules,omitempty" json:"filter_rules,omitempty"`
	NoCodeStats              bool     `yaml:"no_code_stats,omitempty" json:"no_code_stats,omitempty" default:"false"`
	CodeStatsPerComponent    bool     `yaml:"component_code_stats,omitempty" json:"component_code_stats,omitempty" default:"false"`
	PrimaryLanguageThreshold float64  `yaml:"primary_language_threshold,omitempty" json:"primary_language_threshold,omitempty" default:"0.05"`
	UseLockFiles             *bool    `yaml:"use_lock_files,omitempty" json:"use_lock_files,omitempty"` // nil = default (true), explicit false disables
}

ScanOptions represents all configurable scanner options This is the single source of truth for all option fields

type Settings

type Settings struct {
	// Output settings
	OutputFile  string
	PrettyPrint bool
	Aggregate   string

	// Scan behavior
	ExcludePatterns          []string
	Verbose                  bool
	Debug                    bool
	TraceTimings             bool
	TraceRules               bool
	FilterRules              []string // Only use these rules (for debugging)
	NoCodeStats              bool     // Disable code statistics (enabled by default)
	CodeStatsPerComponent    bool     // Enable per-component code statistics (disabled by default)
	RootID                   string   // Override random root ID for deterministic scans
	PrimaryLanguageThreshold float64  // Minimum percentage for primary languages (default 0.05 = 5%)
	UseLockFiles             bool     // Use lock files for dependency resolution (default true)

	// Logging
	LogLevel  slog.Level
	LogFormat string // "text" or "json"
	LogFile   string // Optional: write logs to file instead of stderr
}

Settings holds all scanner configuration Field names match ScanOptions for reflection-based merging

func DefaultSettings

func DefaultSettings() *Settings

DefaultSettings returns default configuration

func LoadSettingsFromEnvironment

func LoadSettingsFromEnvironment() *Settings

LoadSettingsFromEnvironment loads settings from environment variables

func (*Settings) ConfigureLogger

func (s *Settings) ConfigureLogger() *slog.Logger

ConfigureLogger sets up the logger based on settings

func (*Settings) Validate

func (s *Settings) Validate() error

Validate checks if the settings are valid

Jump to

Keyboard shortcuts

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