Skip to content

feat(cmd/gf): init update#4572

Merged
hailaz merged 6 commits intomasterfrom
feat/init
Dec 26, 2025
Merged

feat(cmd/gf): init update#4572
hailaz merged 6 commits intomasterfrom
feat/init

Conversation

@hailaz
Copy link
Contributor

@hailaz hailaz commented Dec 25, 2025

This pull request introduces a significant enhancement to the gf init command by adding support for initializing GoFrame projects from remote templates, including interactive and advanced options for template selection. The changes include new interactive flows, support for remote repositories (including git subdirectories), and modularization of the template initialization logic into a new geninit package.

The most important changes are:

New Features & Interactive Initialization

  • Added support for initializing projects from remote templates via the --repo/-r flag, interactive mode (--interactive/-i), and version selection (--select/-s). Users can now select built-in or remote templates, specify custom repositories, and interactively choose project configuration. (cmd/gf/internal/cmd/cmd_init.go) [1] [2] [3]
  • Introduced interactive prompts for template and project configuration, including project name, module path, and dependency upgrade options. (cmd/gf/internal/cmd/cmd_init.go)

Code Organization & Modularization

  • Extracted remote template initialization logic into a new package, geninit, with a clear API for processing templates, handling Go/gomod/git environments, and managing project generation. (cmd/gf/internal/cmd/geninit/geninit.go)
  • Added helper modules for Go and Git environment checks (geninit_env.go), template downloading (geninit_downloader.go), and AST-based Go import path replacement (geninit_ast.go). [1] [2] [3]

Usability Improvements

  • Updated help and usage documentation to reflect new flags and initialization modes, making it easier for users to discover and use the new features. (cmd/gf/internal/cmd/cmd_init.go)

These changes greatly improve the flexibility and user experience of project initialization in GoFrame, enabling both simple and advanced workflows.

hailaz and others added 4 commits December 18, 2025 23:07
- 实现了通过 go get 下载远程 Go 模块作为模板生成新项目的功能
- 支持嵌套 Go 模块路径和 Git 仓库子目录的模板下载
- 增加了交互式模板选择和版本选择功能
- 自动清理生成项目中的 .git、go.work 等文件
- 支持自定义 go.mod 模块路径和依赖升级到最新版本
- 增加了对 Go 和 Git 环境的检查
- 实现了版本信息获取和选择的功能
Copilot AI review requested due to automatic review settings December 25, 2025 03:58
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR enhances the gf init command with support for initializing GoFrame projects from remote templates, including interactive template selection, version selection, and git subdirectory support. The changes introduce a new geninit package that modularizes template initialization logic and provides both CLI and interactive workflows.

Key changes:

  • Added remote template initialization via --repo/-r flag with support for Git subdirectories
  • Implemented interactive mode (--interactive/-i) for template and configuration selection
  • Added version selection capability (--select/-s) for choosing specific template versions
  • Created modular geninit package with specialized handlers for downloads, AST transformations, and project generation

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 20 comments.

Show a summary per file
File Description
cmd/gf/internal/cmd/cmd_init.go Updated command entry point with new flags, interactive mode, and routing logic for remote vs built-in templates
cmd/gf/internal/cmd/geninit/geninit.go Core orchestration logic for processing remote templates via Go modules or Git subdirectories
cmd/gf/internal/cmd/geninit/geninit_version.go Module version fetching and parsing using go list commands
cmd/gf/internal/cmd/geninit/geninit_selector.go Interactive version selection UI with display limiting
cmd/gf/internal/cmd/geninit/geninit_git_downloader.go Git sparse checkout implementation for subdirectory templates with URL parsing heuristics
cmd/gf/internal/cmd/geninit/geninit_generator.go Project generation logic including file copying, cleanup, and dependency management
cmd/gf/internal/cmd/geninit/geninit_env.go Environment validation for Go and Git installations
cmd/gf/internal/cmd/geninit/geninit_downloader.go Go module download via go get with fallback version strategies
cmd/gf/internal/cmd/geninit/geninit_ast.go AST-based import path replacement for module renaming

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@hailaz hailaz requested a review from houseme December 26, 2025 02:45
@hailaz hailaz merged commit 4d6c7e3 into master Dec 26, 2025
20 checks passed
@hailaz hailaz deleted the feat/init branch December 26, 2025 04:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants