Skip to content

[Subissue 7/7] Template Generation Support (Optional) #41

Closed

Description

@josecelano

Parent Epic: #34 - Implement Create Environment Command
Depends On: #40 - Template System Integration
Status: OPTIONAL ENHANCEMENT
Estimated Time: 1-2 hours

⚠️ Note: This is an optional enhancement that can be deferred. It requires #40 (Template System Integration) to be completed first.

Overview

Implement the template subcommand for the create command, allowing users to generate configuration file templates. This enhances user experience by providing a starting point for configuration creation.

Goals

  • Implement template subcommand in the create command structure
  • Generate JSON configuration template files
  • Support custom output paths for template generation
  • Provide helpful placeholder content with clear replacement instructions
  • Integrate with existing CLI subcommand architecture

Architecture Requirements

DDD Layer: Presentation (CLI interface) + Infrastructure (template generation)
Module Path: src/presentation/console/subcommands/create/ + src/infrastructure/templates/
Pattern: CLI Subcommand + Template Generation

Dependencies: Requires #40 (Template System Integration) to be completed first.

CLI Interface

# Generate template configuration file (JSON format)
torrust-tracker-deployer create template
# Creates: ./environment-template.json in current working directory

# Generate template in specific directory
torrust-tracker-deployer create template ./config/environment.json

# Generate template with custom filename
torrust-tracker-deployer create template ./my-environment.json

# Show help for template subcommand
torrust-tracker-deployer create template --help

Template Example

{
  "environment": {
    "name": "my-environment"
  },
  "ssh_credentials": {
    "private_key_path": "~/.ssh/id_rsa",
    "public_key_path": "~/.ssh/id_rsa.pub",
    "username": "torrust",
    "port": 22
  }
}

Acceptance Criteria

  • create template subcommand generates valid JSON template
  • Template includes helpful placeholder values
  • Template includes comments explaining each field (if JSON supports it, or in separate docs)
  • Custom output paths are supported
  • Default filename is environment-template.json
  • Error handling follows tiered help system pattern
  • Help text provides clear usage examples

Implementation Notes

  • Extend existing CLI subcommand structure from Subissue 3
  • Use TemplateManager from Subissue 6 for template generation
  • Follow existing patterns for CLI subcommands
  • Ensure template content matches environment configuration schema

For detailed specification, see: docs/issues/epic-create-environment-command-subissue-7-template-generation-support.md

Activity

  1. added
    enhancement
    on Oct 25, 2025
  2. added 2 commits that reference this issue on Oct 25, 2025
  3. josecelano commented on Oct 27, 2025

    @josecelano
    MemberAuthor

    ✅ Issue Documentation Updated

    The issue specification has been updated to reflect the implementation completed in PR #48.

    Key Changes

    Previous specification was outdated - it was written before PR #48 implemented struct-based template generation in the domain layer.

    New v2 specification: docs/issues/41-subissue-7-template-generation-support-v2.md

    What Changed

    1. Architecture: Domain layer (not infrastructure) - template generation already implemented
    2. Implementation scope: Thin CLI wrapper only (1-2 hours of work)
    3. API: Use existing EnvironmentCreationConfig::generate_template_file() method
    4. Error handling: Use existing CreateConfigError enum
    5. Testing: Focus on CLI integration tests (domain logic already tested)

    What's Already Done ✅

    • Template generation logic in src/domain/config/environment_config.rs
    • Error handling with .help() methods
    • Comprehensive test coverage in domain layer
    • JSON template format with placeholders

    What Needs to Be Done

    • Add template subcommand to CLI argument parser
    • Implement handler to call existing domain method
    • Add user-friendly success messages
    • Write CLI integration tests

    Why This Makes Implementation Easier

    The hard work (template generation, error handling, validation) is already complete. This issue is now just about exposing that functionality through a CLI subcommand - a straightforward CLI integration task.

    For Implementation

    @copilot When implementing this:

    • DO call EnvironmentCreationConfig::generate_template_file(&path).await
    • DON'T create new template generation logic
    • DON'T create src/infrastructure/templates/ module
    • DO keep it simple - this is just a thin CLI wrapper

    See the v2 specification for complete implementation details with code examples.

  4. added a commit that references this issue on Oct 27, 2025
  5. added a commit that references this issue on Oct 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementoptional

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions