Skip to content

Add version subcommand to report gorm-cli build version#33

Merged
jinzhu merged 4 commits intogo-gorm:masterfrom
miladev95:add-version-command
Dec 22, 2025
Merged

Add version subcommand to report gorm-cli build version#33
jinzhu merged 4 commits intogo-gorm:masterfrom
miladev95:add-version-command

Conversation

@miladev95
Copy link
Contributor

@miladev95 miladev95 commented Dec 10, 2025

  • Do only one thing
  • Non breaking API changes
  • Tested

What did this pull request do?

Adds a version subcommand that prints the current CLI version. The version can be set at build time using -ldflags "-X main.Version=x.y.z" and defaults to v0.2.4. This helps users identify which version they have installed for troubleshooting and bug reports.


Add CLI version subcommand using Go build metadata

Adds a new version subcommand to the CLI root command that reports the build version of gorm-cli. The command inspects debug.ReadBuildInfo() at runtime, printing info.Main.Version when populated and falling back to dev when the binary lacks module version metadata.

Key Changes

• Imported runtime/debug in main.go to access Go build metadata
• Registered the new versionCmd() with the root Cobra command alongside gen.New()
• Implemented versionCmd() to emit gorm-cli version <version> with a fallback to dev when debug.ReadBuildInfo() is unavailable or returns (devel)

Affected Areas

main.go


This summary was automatically generated by @propel-code-bot

@propel-code-bot propel-code-bot bot changed the title Add version command Add CLI version command to display build version Dec 10, 2025
@jinzhu
Copy link
Member

jinzhu commented Dec 22, 2025

Hi @miladev95

Thank you for your PR, to ensure the version is automatically synced with Git tags, I suggest using runtime/debug to avoid manual string updates

e.g:

func getVersion() string {
	if info, ok := debug.ReadBuildInfo(); ok {
		if info.Main.Version != "" && info.Main.Version != "(devel)" {
			return info.Main.Version
		}
	}

	return "dev"
}

@propel-code-bot propel-code-bot bot changed the title Add CLI version command to display build version Add version subcommand to report gorm-cli build version Dec 22, 2025
main.go Outdated
}
}

func getVersion() string {
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps we should move this implementation into the versionCmd method?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right it's cleaner, i moved into the versionCmd method.

Copy link
Member

Choose a reason for hiding this comment

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

Thank you for your PR

@jinzhu jinzhu merged commit a9cba09 into go-gorm:master Dec 22, 2025
3 checks passed
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.

2 participants