Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix(cmd/gf): improve init command with version retry and gofmt support#4592

Merged
hailaz merged 2 commits intomasterfrom
fix/gfinit0107
Jan 7, 2026
Merged

fix(cmd/gf): improve init command with version retry and gofmt support#4592
hailaz merged 2 commits intomasterfrom
fix/gfinit0107

Conversation

@hailaz
Copy link
Contributor

@hailaz hailaz commented Jan 7, 2026

No description provided.

@hailaz hailaz requested review from Copilot and houseme January 7, 2026 04:13
@hailaz hailaz changed the title feat(cmd/gf): improve init command with version retry and gofmt support fix(cmd/gf): improve init command with version retry and gofmt support Jan 7, 2026
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 by adding version retry logic when a specified version fails to download, and ensures consistent code formatting across all generated project files.

  • Added automatic version selection fallback when a user-specified version fails to download
  • Integrated utils.GoFmt to format generated Go files in both custom and built-in template flows
  • Replaced go/printer with go/format in AST replacer for standard formatting

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
cmd/gf/internal/cmd/geninit/geninit_generator.go Added utils.GoFmt call to format all generated Go files after project generation
cmd/gf/internal/cmd/geninit/geninit_ast.go Switched from printer.Config to format.Node for standard Go formatting in AST-based import replacement
cmd/gf/internal/cmd/geninit/geninit.go Implemented version retry logic that offers version selection when a user-specified version download fails
cmd/gf/internal/cmd/cmd_init.go Added utils.GoFmt call for built-in template path and updated usage examples to demonstrate version specification

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

Copy link
Contributor

Copilot AI commented Jan 7, 2026

@hailaz I've opened a new pull request, #4594, to work on those changes. Once the pull request is ready, I'll request review from you.

Addresses feedback from [PR
#4592](#4592 (comment))
regarding inefficient double formatting of Go files during project
generation.

## Changes

- Replace `format.Node` with `printer.Fprint` in AST replacer to skip
intermediate formatting
- Defer all formatting to final `utils.GoFmt` call which uses
`golang.org/x/tools/imports`

Previously, files modified by the AST replacer were formatted twice—once
during import path replacement and again by the final `utils.GoFmt`
call. Now the AST replacer writes unformatted AST, and a single
`utils.GoFmt` pass handles both formatting and import organization.

```go
// Before: formatted output
if err := format.Node(&buf, r.fset, file); err != nil {
    return err
}

// After: unformatted output, formatting deferred
if err := printer.Fprint(&buf, r.fset, file); err != nil {
    return err
}
```

<!-- START COPILOT CODING AGENT TIPS -->
---

✨ Let Copilot coding agent [set things up for
you](https://github.com/gogf/gf/issues/new?title=✨+Set+up+Copilot+instructions&body=Configure%20instructions%20for%20this%20repository%20as%20documented%20in%20%5BBest%20practices%20for%20Copilot%20coding%20agent%20in%20your%20repository%5D%28https://gh.io/copilot-coding-agent-tips%29%2E%0A%0A%3COnboard%20this%20repo%3E&assignees=copilot)
— coding agent works faster and does higher quality work when set up for
your repo.

---------

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: hailaz <[email protected]>
@hailaz hailaz merged commit 8f826ed into master Jan 7, 2026
32 checks passed
@hailaz hailaz deleted the fix/gfinit0107 branch January 7, 2026 08:20
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