Implement 'barn config' commands #21

Closed
opened 2026-10-04 19:28:25 +00:00 by daniel · 1 comment
Owner

Imported from GitHub samson-media/barn#21 — opened by @daniel-samson on 2026-01-21 12:43:12 UTC

Overview

Implement the barn config command for configuration validation and display.

Context

  • Read first: docs/config.md (configuration options)
  • Depends on: #8 (CLI framework), #2 (configuration system)

Requirements

1. Config Command Group

com.samsonmedia.barn.cli.ConfigCommand.java:

@Command(
    name = "config",
    description = "Configuration management",
    subcommands = {
        ConfigShowCommand.class,
        ConfigValidateCommand.class,
        ConfigInitCommand.class
    }
)
public class ConfigCommand extends BaseCommand { }

2. barn config show

Show effective configuration (merged from file, defaults, and env):

@Command(name = "show", description = "Show effective configuration")
public class ConfigShowCommand extends BaseCommand {
    @Option(names = {"--defaults"}, description = "Show only default values")
    private boolean showDefaults;

    @Override
    public Integer call() {
        Config config = ConfigLoader.load(globalOptions.getConfigPath());
        output(config);
        return 0;
    }
}

Human output:

Barn Configuration
==================
Config file: /etc/barn/barn.conf

[service]
log_level = info
max_concurrent_jobs = 4
heartbeat_interval_seconds = 5
ipc_socket = /tmp/barn/barn.sock
stale_heartbeat_threshold_seconds = 30

[jobs]
default_timeout_seconds = 3600
max_retries = 3
retry_delay_seconds = 30
retry_backoff_multiplier = 2.0
retry_on_exit_codes = []

[cleanup]
enabled = true
max_age_hours = 72
cleanup_interval_minutes = 60
keep_failed_jobs = true
keep_failed_jobs_hours = 168

[storage]
base_dir = /tmp/barn
max_disk_usage_gb = 50
preserve_work_dir = false

3. barn config validate

Validate a configuration file:

@Command(name = "validate", description = "Validate configuration file")
public class ConfigValidateCommand extends BaseCommand {
    @Option(names = {"--config", "-c"}, description = "Config file to validate")
    private Path configFile;

    @Override
    public Integer call() {
        List<ValidationError> errors = ConfigValidator.validate(configFile);
        if (errors.isEmpty()) {
            output("Configuration is valid");
            return 0;
        } else {
            outputErrors(errors);
            return 1;
        }
    }
}

Error output:

Configuration errors in /etc/barn/barn.conf:

  Line 5: Invalid value for 'max_concurrent_jobs': must be positive integer
  Line 12: Unknown key 'retry_multiplier' in [jobs] section
  Line 20: Invalid value for 'log_level': must be one of debug, info, warn, error

4. barn config init

Create a new configuration file with defaults:

@Command(name = "init", description = "Create default configuration file")
public class ConfigInitCommand extends BaseCommand {
    @Option(names = {"--path", "-p"}, description = "Output path")
    private Path outputPath;

    @Option(names = {"--force", "-f"}, description = "Overwrite existing file")
    private boolean force;

    @Override
    public Integer call() {
        // Generate default config and write to file
    }
}

5. Configuration Validator

public class ConfigValidator {
    public static List<ValidationError> validate(Path configFile) {
        List<ValidationError> errors = new ArrayList<>();

        // Parse file
        // Check each value type and range
        // Check for unknown keys
        // Check for missing required keys

        return errors;
    }

    public record ValidationError(int line, String key, String message) { }
}

Validation rules:

  • Positive integers for all count/duration values
  • Valid enum values for log_level
  • Valid paths for base_dir, ipc_socket
  • Multiplier > 1.0 for retry_backoff_multiplier
  • max_age_hours > 0

6. Tests Required

  • ConfigShowCommandTest.java: Test output formatting
  • ConfigValidateCommandTest.java: Test validation errors
  • ConfigInitCommandTest.java: Test file generation
  • ConfigValidatorTest.java: Test all validation rules

Acceptance Criteria

  • barn config show displays effective config
  • barn config validate catches errors with line numbers
  • barn config init creates valid default config
  • JSON/XML output formats work
  • Environment overrides shown in output
  • mvn verify passes
  • Tests have 80%+ coverage

Implementation Notes

Show which values came from which source:

[service]
log_level = debug        # from environment: BARN_SERVICE_LOG_LEVEL
max_concurrent_jobs = 8  # from /etc/barn/barn.conf
heartbeat_interval = 5   # default

For init, generate commented template:

# Barn Configuration
# See docs/config.md for full documentation

[service]
# Logging verbosity: debug, info, warn, error
log_level = "info"

# Maximum jobs running simultaneously
max_concurrent_jobs = 4

Definition of Done

  • Config commands work correctly
  • Validation catches common errors
  • Init creates usable config
  • All tests pass
<!-- github-import:issue:21 --> _Imported from GitHub samson-media/barn#21 — opened by **@daniel-samson** on 2026-01-21 12:43:12 UTC_ ## Overview Implement the `barn config` command for configuration validation and display. ## Context - **Read first**: `docs/config.md` (configuration options) - **Depends on**: #8 (CLI framework), #2 (configuration system) ## Requirements ### 1. Config Command Group `com.samsonmedia.barn.cli.ConfigCommand.java`: ```java @Command( name = "config", description = "Configuration management", subcommands = { ConfigShowCommand.class, ConfigValidateCommand.class, ConfigInitCommand.class } ) public class ConfigCommand extends BaseCommand { } ``` ### 2. barn config show Show effective configuration (merged from file, defaults, and env): ```java @Command(name = "show", description = "Show effective configuration") public class ConfigShowCommand extends BaseCommand { @Option(names = {"--defaults"}, description = "Show only default values") private boolean showDefaults; @Override public Integer call() { Config config = ConfigLoader.load(globalOptions.getConfigPath()); output(config); return 0; } } ``` Human output: ``` Barn Configuration ================== Config file: /etc/barn/barn.conf [service] log_level = info max_concurrent_jobs = 4 heartbeat_interval_seconds = 5 ipc_socket = /tmp/barn/barn.sock stale_heartbeat_threshold_seconds = 30 [jobs] default_timeout_seconds = 3600 max_retries = 3 retry_delay_seconds = 30 retry_backoff_multiplier = 2.0 retry_on_exit_codes = [] [cleanup] enabled = true max_age_hours = 72 cleanup_interval_minutes = 60 keep_failed_jobs = true keep_failed_jobs_hours = 168 [storage] base_dir = /tmp/barn max_disk_usage_gb = 50 preserve_work_dir = false ``` ### 3. barn config validate Validate a configuration file: ```java @Command(name = "validate", description = "Validate configuration file") public class ConfigValidateCommand extends BaseCommand { @Option(names = {"--config", "-c"}, description = "Config file to validate") private Path configFile; @Override public Integer call() { List<ValidationError> errors = ConfigValidator.validate(configFile); if (errors.isEmpty()) { output("Configuration is valid"); return 0; } else { outputErrors(errors); return 1; } } } ``` Error output: ``` Configuration errors in /etc/barn/barn.conf: Line 5: Invalid value for 'max_concurrent_jobs': must be positive integer Line 12: Unknown key 'retry_multiplier' in [jobs] section Line 20: Invalid value for 'log_level': must be one of debug, info, warn, error ``` ### 4. barn config init Create a new configuration file with defaults: ```java @Command(name = "init", description = "Create default configuration file") public class ConfigInitCommand extends BaseCommand { @Option(names = {"--path", "-p"}, description = "Output path") private Path outputPath; @Option(names = {"--force", "-f"}, description = "Overwrite existing file") private boolean force; @Override public Integer call() { // Generate default config and write to file } } ``` ### 5. Configuration Validator ```java public class ConfigValidator { public static List<ValidationError> validate(Path configFile) { List<ValidationError> errors = new ArrayList<>(); // Parse file // Check each value type and range // Check for unknown keys // Check for missing required keys return errors; } public record ValidationError(int line, String key, String message) { } } ``` Validation rules: - Positive integers for all count/duration values - Valid enum values for log_level - Valid paths for base_dir, ipc_socket - Multiplier > 1.0 for retry_backoff_multiplier - max_age_hours > 0 ### 6. Tests Required - `ConfigShowCommandTest.java`: Test output formatting - `ConfigValidateCommandTest.java`: Test validation errors - `ConfigInitCommandTest.java`: Test file generation - `ConfigValidatorTest.java`: Test all validation rules ## Acceptance Criteria - [ ] `barn config show` displays effective config - [ ] `barn config validate` catches errors with line numbers - [ ] `barn config init` creates valid default config - [ ] JSON/XML output formats work - [ ] Environment overrides shown in output - [ ] `mvn verify` passes - [ ] Tests have 80%+ coverage ## Implementation Notes Show which values came from which source: ``` [service] log_level = debug # from environment: BARN_SERVICE_LOG_LEVEL max_concurrent_jobs = 8 # from /etc/barn/barn.conf heartbeat_interval = 5 # default ``` For init, generate commented template: ```toml # Barn Configuration # See docs/config.md for full documentation [service] # Logging verbosity: debug, info, warn, error log_level = "info" # Maximum jobs running simultaneously max_concurrent_jobs = 4 ``` ## Definition of Done - Config commands work correctly - Validation catches common errors - Init creates usable config - All tests pass
daniel added this to the M3: CLI Commands milestone 2026-10-04 19:28:25 +00:00
daniel added the cli label 2026-10-04 19:28:25 +00:00
Author
Owner

@daniel-samson commented on 2026-01-21 15:29:33 UTC:

Completed barn config commands implementation:

Changes

  • ConfigShowCommand: Shows effective configuration with support for --defaults flag and all output formats
  • ConfigValidateCommand: Validates TOML configuration files with detailed error reporting
  • ConfigInitCommand: Creates default configuration file with comments and documentation

Tests

  • 28 new tests added covering all config command functionality
  • All 793 tests pass
  • Coverage thresholds met

Usage Examples

# Show effective configuration
barn config show

# Show default values only
barn config show --defaults

# Output as JSON
barn config show --output JSON --defaults

# Validate a config file
barn config validate --file /path/to/config.toml

# Create default config file
barn config init --path ~/.config/barn/barn.toml

# Force overwrite existing config
barn config init --path ~/.config/barn/barn.toml --force
<!-- github-import:comment:3778850709 --> _**@daniel-samson** commented on 2026-01-21 15:29:33 UTC:_ Completed barn config commands implementation: ## Changes - **ConfigShowCommand**: Shows effective configuration with support for --defaults flag and all output formats - **ConfigValidateCommand**: Validates TOML configuration files with detailed error reporting - **ConfigInitCommand**: Creates default configuration file with comments and documentation ## Tests - 28 new tests added covering all config command functionality - All 793 tests pass - Coverage thresholds met ## Usage Examples ```bash # Show effective configuration barn config show # Show default values only barn config show --defaults # Output as JSON barn config show --output JSON --defaults # Validate a config file barn config validate --file /path/to/config.toml # Create default config file barn config init --path ~/.config/barn/barn.toml # Force overwrite existing config barn config init --path ~/.config/barn/barn.toml --force ```
This repo is archived. You cannot comment on issues.