中文文档请参阅 README.zh.md。
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.
- 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.
Clone a template and generate a project in one command:
gogen --git=https://github.com/example/template
-
Using Go:
go install github.com/yourusername/gogen@latest
-
Manual Build:
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.
Generate a project from a Git repository:
gogen --git=https://github.com/example/template --branch=main
Generate a project from a local template:
gogen --local=/path/to/template
Follow the interactive prompts to specify a project name (or accept the default derived from the template source).
- Go: 1.24 or later (for building from source).
- Git: Required only for cloning remote templates.
Below is an example of running gogen
with a Git repository:
$ 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!
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
We welcome contributions! Please see CONTRIBUTING.md for guidelines on how to report issues, submit pull requests, or improve the project.
Paxon Qiao 乔鹏军 🖋 |
||||||
|
This project is licensed under the MIT License.