- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 136
feat(cli): Add template system for project initialization #676
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Open
      
      
            ishaksebsib
  wants to merge
  9
  commits into
  HelixDB:dev
  
    
      
        
          
  
    
      Choose a base branch
      
     
    
      
        
      
      
        
          
          
        
        
          
            
              
              
              
  
           
        
        
          
            
              
              
           
        
       
     
  
        
          
            
          
            
          
        
       
    
      
from
ishaksebsib:feat/cli-template
  
      
      
   
  
    
  
  
  
 
  
      
    base: dev
Could not load branches
            
              
  
    Branch not found: {{ refName }}
  
            
                
      Loading
              
            Could not load tags
            
            
              Nothing to show
            
              
  
            
                
      Loading
              
            Are you sure you want to change the base?
            Some commits from the old base branch may be removed from the timeline,
            and old review comments may become outdated.
          
          Conversation
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
    There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
7 files reviewed, 3 comments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
3 files reviewed, no comments
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
      
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Description
Adds a complete template system to the Helix CLI, allowing users to initialize projects from Git-based templates with Handlebars variable substitution and caching.
Key Features
Template Sources:
helix init --template <template-name>helix init --template <template-name>@v1.0helix init --template https://github.com/user/repo@mainhelix init --template [email protected]:user/repo.git@v2Caching System:
~/.helix/templates/<url_hash>/<commit_hash>/git ls-remoteto check for updatesTemplate Processing:
{{project_name}}).hbsfile extension support for template filesUser Experience:
Implementation Details
New Files:
commands/templates/mod.rs- Template source parsing and configurationcommands/templates/fetcher.rs- Git operations, caching, and cache validationcommands/templates/processor.rs- Handlebars rendering and file copyingDependencies:
handlebars = "6.3.2"for template renderingtempfile = "3.23.0"for temporary filesModified Files:
commands/init.rs- Integrated template processing into the init flowcommands/mod.rs- Exposed templates moduleRelated Issues
None
Checklist when merging to main
rustfmthelix-cli/Cargo.tomlandhelixdb/Cargo.tomlAdditional Notes
None
Greptile Overview
Updated On: 2025-10-30 07:55:59 UTC
Greptile Summary
Implements a complete Git-based template system for the Helix CLI that enables project initialization from official or custom templates with Handlebars variable substitution. The implementation includes a sophisticated commit-hash based caching mechanism with network resilience and atomic operations.
Architecture Highlights:
mod.rs(URL parsing),fetcher.rs(Git operations & caching),processor.rs(Handlebars rendering)~/.helix/templates/{url_hash}/{commit_hash}/ensures immutability and proper invalidationgit ls-remotechecks for updates, with graceful fallback to cached versions when offlinehelix.tomlorhelix.toml.hbsexists before processingImplementation Quality:
.gitignore),.gitdirectories filtered[email protected]:user/repo.git@v2) and HTTPS URLs with@in usernamesinit.rsintegration maintains existing project protection (checks forhelix.tomlbefore processing)Previous Review Comments Addressed:
db4d905c): Atomic rendering now uses temp directories within the base cache dir with atomic rename723a8865): Explicitly checks and skips symlinks during renderingTempDirRAII patternCode is production-ready with no critical issues found.
Important Files Changed
File Analysis
TemplateSourceenum for parsing official templates and Git URLs with comprehensive URL parsing logic and unit tests.hbsextension removal, skips symlinks and hidden files (except.gitignore), and correctly skips.gitdirectoriestemplateparameter from unusedStringto functionalOption<String>, maintains existing project protection checkSequence Diagram
sequenceDiagram participant User participant CLI as helix init participant Init as init.rs participant Parser as TemplateSource::parse participant Fetcher as TemplateFetcher participant Git as Git Commands participant Cache as ~/.helix/templates participant Processor as TemplateProcessor participant HBS as Handlebars participant Project as Project Directory User->>CLI: helix init --template [email protected] CLI->>Init: run(template: Some("[email protected]")) Init->>Init: Check helix.toml exists Init->>Init: Create project directory Init->>Parser: parse("[email protected]") Parser-->>Init: TemplateSource::Official{name: "basic", git_ref: Some("v1.0")} Init->>Fetcher: fetch(source, variables) Fetcher->>Git: git --version Git-->>Fetcher: version info Fetcher->>Fetcher: check_cache_validity(source) Fetcher->>Git: git ls-remote https://github.com/HelixDB/basic v1.0 alt Network Success Git-->>Fetcher: commit_hash: abc123... Fetcher->>Cache: Check if abc123 exists alt Cache Valid Cache-->>Fetcher: Cache exists Fetcher-->>Init: Return cache_path else Cache Invalid Fetcher->>Fetcher: fetch_and_render(source, variables) Fetcher->>Git: git clone --depth 1 --branch v1.0 Git-->>Fetcher: Clone to temp directory Fetcher->>Fetcher: validate_template (check helix.toml/helix.toml.hbs) Fetcher->>Fetcher: render_and_cache Fetcher->>Processor: render_to_cache(temp_dir, temp_cache_dir, variables) loop For each file/directory alt File ends with .hbs Processor->>HBS: render_template(content, variables) HBS-->>Processor: rendered content Processor->>Cache: Write to temp cache (remove .hbs extension) else Regular file Processor->>Cache: Copy to temp cache else Directory Processor->>Processor: Recurse into directory end end Processor-->>Fetcher: Rendering complete Fetcher->>Cache: Atomic rename temp_cache_dir to abc123 Fetcher-->>Init: Return cache_path end else Network Error Git-->>Fetcher: Network error Fetcher->>Cache: Check for any cached version alt Cache Exists Cache-->>Fetcher: Return latest cached version Fetcher-->>Init: Return cache_path (with warning) else No Cache Fetcher-->>Init: Error: network error and no cache end end Init->>Processor: process(cache_dir, project_dir) loop For each cached file alt Is .git directory Processor->>Processor: Skip else Is directory Processor->>Project: Create directory and recurse else Is file Processor->>Project: Copy file end end Processor-->>Init: Copy complete Init-->>User: Success message with next steps