Skip to content

Conversation

@httpdss
Copy link
Owner

@httpdss httpdss commented Oct 29, 2025

Description

This PR implements support for the STRUCTKIT_STRUCTURES_PATH environment variable to address #122.

Changes

  • Add environment variable support: Users can now set STRUCTKIT_STRUCTURES_PATH to specify a default structures path without repeating the -s flag on every command
  • Precedence: Command-line arguments take precedence over environment variables (consistent with existing patterns)
  • Logging: When the environment variable is used, a log message is emitted for transparency
  • Testing: Comprehensive test suite covering all precedence scenarios
  • Documentation: Updated CLI reference with environment variables section and generate command documentation

Implementation Details

  • Modified GenerateCommand.execute() to check for STRUCTKIT_STRUCTURES_PATH environment variable when --structures-path is not provided
  • Follows the existing pattern used by STRUCTKIT_LOG_LEVEL
  • All tests pass successfully

Usage Example

export STRUCTKIT_STRUCTURES_PATH=~/custom-structures
structkit generate python-basic ./my-project
# Equivalent to: structkit generate -s ~/custom-structures python-basic ./my-project

Testing

  • ✅ 5 new tests covering:

    • Environment variable is used when no CLI arg provided
    • CLI argument takes precedence over environment variable
    • No structures path when env var not set
    • Logging message is emitted
    • Empty env var is ignored
  • ✅ All existing tests continue to pass

  • ✅ Pre-commit hooks pass (formatting, linting)

Closes

Closes #122

- Add STRUCTKIT_STRUCTURES_PATH env var support for --structures-path argument
- CLI argument takes precedence over environment variable
- Add comprehensive test suite covering all precedence scenarios
- Update CLI documentation with environment variables section
- Update generate command docs to mention the new env var
@httpdss httpdss requested a review from Copilot October 29, 2025 22:11
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds support for the STRUCTKIT_STRUCTURES_PATH environment variable to provide a convenient way to set a default structures path without repeating the -s flag on every command.

  • Environment variable support with proper CLI precedence (command-line arguments override environment variables)
  • Logging transparency when the environment variable is used
  • Comprehensive test coverage for all precedence scenarios

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
tests/test_env_var_structures_path.py Comprehensive test suite covering environment variable precedence, CLI override, logging, and edge cases
structkit/commands/generate.py Implementation of environment variable resolution logic in the execute method
docs/cli-reference.md Updated documentation with environment variables section and usage examples

- Set default value directly in argument parser instead of handling in execute()
- Cleaner and more idiomatic argparse usage
- Same functionality and precedence behavior
- Update all tests to re-create parsers with env vars set
- This ensures os.getenv() is called during GenerateCommand.__init__
- Add logging when STRUCTKIT_STRUCTURES_PATH environment variable is used
- All 5 tests now pass successfully
@httpdss httpdss added the minor label Oct 29, 2025
@httpdss httpdss merged commit 9667730 into main Oct 29, 2025
3 checks passed
@httpdss httpdss deleted the feature/env-var-structures-path branch October 29, 2025 22:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature: Support setting structures-path via environment variable

2 participants