https://github.com/qiaopengjun5162/gogen
A lightweight tool to generate projects from Git repositories or local templates with ease.
https://github.com/qiaopengjun5162/gogen
cli code-generation generator go template template-engine tool
Last synced: about 1 month ago
JSON representation
A lightweight tool to generate projects from Git repositories or local templates with ease.
- Host: GitHub
- URL: https://github.com/qiaopengjun5162/gogen
- Owner: qiaopengjun5162
- License: mit
- Created: 2025-02-27T06:44:54.000Z (3 months ago)
- Default Branch: main
- Last Pushed: 2025-03-26T13:31:49.000Z (2 months ago)
- Last Synced: 2025-03-26T13:41:54.201Z (2 months ago)
- Topics: cli, code-generation, generator, go, template, template-engine, tool
- Language: Go
- Homepage:
- Size: 25.4 KB
- Stars: 8
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
# gogen
[](#contributors-)


## Chinese Documentation
中文文档请参阅 [README.zh.md](README.zh.md)。
## Overview
`gogen` is a lightweight project generation tool designed to scaffold new projects from Git repositories or local
templates. It streamlines the process by cloning from a Git URL (with optional branch specification) or copying from a
local path, while supporting basic template variable substitution.### Features
- Clone project templates from Git repositories (e.g., GitHub, GitLab).
- Copy templates from local directories.
- Specify a Git branch for cloning (optional).
- Replace template variables (e.g., `{{project_name}}`) with user-provided values.
- Interactive CLI with ANSI-colored output and progress tracking.
- Embedded Git commit hash for version tracking.### Quick Start
Clone a template and generate a project in one command:
```bash
gogen --git=https://github.com/example/template
```### Installation
1. **Using Go**:
```bash
go install github.com/yourusername/gogen@latest
```2. **Manual Build**:
```bash
git clone https://github.com/yourusername/gogen.git
cd gogen
go build -v -ldflags "-X main.GitCommit=$(git rev-parse --short HEAD)" -o gogen ./main.go
```This embeds the Git commit hash into the binary, visible when running the tool.
### Usage
Generate a project from a Git repository:
```bash
gogen --git=https://github.com/example/template --branch=main
```Generate a project from a local template:
```bash
gogen --local=/path/to/template
```Follow the interactive prompts to specify a project name (or accept the default derived from the template source).
### Requirements
- **Go**: 1.24 or later (for building from source).
- **Git**: Required only for cloning remote templates.### Example Output
Below is an example of running `gogen` with a Git repository:
```bash
$ gogen --git=https://github.com/example/template
[INFO] Built from Git commit: abc1234
[INFO] Validating input...
[INPUT] Enter project name (default: template): myproject
[INPUT] Generate project 'myproject' from https://github.com/example/template? (Y/n): Y
[PROGRESS] Cloning Git repository from 'https://github.com/example/template'...
[SUCCESS] Project 'myproject' generated successfully!➜ gogen --git=https://github.com/qiaopengjun5162/gotcha
[INFO] Validating input...
[INPUT] Enter project name (default: gotcha):
[INPUT] Generate project 'gotcha' from https://github.com/qiaopengjun5162/gotcha? (Y/n):
[INFO] Generating project 'gotcha'...
[PROGRESS] Cloning Git repository from 'https://github.com/qiaopengjun5162/gotcha'...
正克隆到 'gotcha'...
remote: Enumerating objects: 26, done.
remote: Counting objects: 100% (26/26), done.
remote: Compressing objects: 100% (22/22), done.
remote: Total 26 (delta 1), reused 22 (delta 1), pack-reused 0 (from 0)
接收对象中: 100% (26/26), 10.39 KiB | 5.20 MiB/s, 完成.
处理 delta 中: 100% (1/1), 完成.
[SUCCESS] Project 'gotcha' generated successfully!➜ gogen --git=https://github.com/qiaopengjun5162/gotcha
[INFO] Validating input...
[INPUT] Enter project name (default: gotcha): myproject
[INPUT] Generate project 'myproject' from https://github.com/qiaopengjun5162/gotcha? (Y/n): y
[INFO] Generating project 'myproject'...
[PROGRESS] Cloning Git repository from 'https://github.com/qiaopengjun5162/gotcha'...
正克隆到 'myproject'...
remote: Enumerating objects: 26, done.
remote: Counting objects: 100% (26/26), done.
remote: Compressing objects: 100% (22/22), done.
remote: Total 26 (delta 1), reused 22 (delta 1), pack-reused 0 (from 0)
接收对象中: 100% (26/26), 10.39 KiB | 5.20 MiB/s, 完成.
处理 delta 中: 100% (1/1), 完成.
[SUCCESS] Project 'myproject' generated successfully!```
### Project Structure
```
gogen/
├── CHANGELOG.md # Version history
├── LICENSE # Project license
├── Makefile # Build automation
├── README.md # This file
├── README.zh.md # Chinese documentation
├── go.mod # Go module file
├── main.go # Main source file
```### Contributing
We welcome contributions! Please see [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines on how to report issues, submit
pull requests, or improve the project.## Contributors
Paxon Qiao 乔鹏军
🖋
![]()
Add your contributions
### License
This project is licensed under the [MIT License](LICENSE).