Template CLI: A Powerful Tool for Managing Project Templates
Mar 10. 2025

AI Summary
This AI-generated content is derived from the source article and has been manually verified.
Loading.

Template CLI 🚀

A convenient project template management tool for quickly cloning templates from Git repositories.

Features

  • ✅ Interactive template selection
  • ✅ Flexible configuration via command-line arguments
  • ✅ Intelligent cache configuration management
  • ✅ Support for branch specification and directory renaming
  • âš¡ Native JSON project selection mode

Installation

Install via Cargo

cargo install --path .

Manual Build

git clone https://github.com/your-repo/project-template.git
cd project-template
cargo build --release

Usage Guide

Basic Command Structure

template-cli [options]

Quick Start Examples

# Clone a template project (interactive selection)
template-cli https://github.com/my-repo/templates

# Clone with specific parameters
template-cli -r https://github.com/my-repo -b dev -d ./new-project -t my_template

# View cache configuration
template-cli -x

# Use native project selection mode
template-cli --original https://github.com/my-repo.json

Parameter Description

ParameterDescriptionDefault Value
-r, --repoGit repository URL to clone-
-b, --branchGit branch namemain
-d, --target-dirTarget directory for the templateCurrent dir
-t, templateSpecific template to useInteractive
-o, --originalUse native JSON configuration-
-c, --clear-cacheClear configuration cache-
-x, --check-cacheView saved configuration cache-

Advanced Parameters

  • Intelligent Cache: Automatically saves recently used repositories, branches, etc., and prioritizes cache on reuse.

    • View cache: template-cli -x
    • Clear cache: template-cli -c
  • Native Project Selection Mode: Use the --original parameter to specify a JSON configuration file URL, which displays a selection interface like this:

    Category:
    1. Frontend Projects
    2. Backend Projects
    
    Select a category (default: Frontend Projects):

Workflow

  1. User inputs parameters or selects interactive mode.
  2. Determine repository information based on parameters/cache.
  3. Clone the repository from the specified branch to a temporary directory.
  4. Display available templates for user selection.
  5. Copy the selected template to the target path.
  6. Automatically clean up temporary files and output success message.

FAQ

Q: Where is the cache stored?

~/.tmpl-cli/{.template_cli_cache.json}

Q: How to completely reset the configuration?

rm -rf ~/.tmpl-cli && template-cli --clear-cache

Q: Supported template repository structure?

<repository>/
├── template1/
├── template2/
└── .gitignore

Developer Guide

Code Structure

src/
├── cache.rs    # Cache module
├── cli.rs      # Command-line parsing
├── errors.rs   # Error handling
├── git.rs      # Git operations
├── original.rs # Native mode implementation
├── utils.rs    # Utility methods
└── template.rs # Core template handling

Contribution Guide

  1. Fork this repository.
  2. Create a feature branch: git checkout -b feature/X.
  3. Implement the feature and test it.
  4. Create a Pull Request.
> comment on / twitter
>
CC BY-NC-SA 4.0 2021-PRESENT © Ryan uo