-
Notifications
You must be signed in to change notification settings - Fork 5
Open
Labels
area/customizationEnables default behavior customizationEnables default behavior customization
Milestone
Description
Description
Add option to exclude a given version fields. Currently, all fields are displayed:
Version (devel)
Git Commit d03329a
Build Date 30 Jul 22 14:08 CEST (3 seconds ago)
Commit Date 30 Jul 22 13:42 CEST (26 minutes ago)
Dirty Build yes
Go Version 1.18.2
Compiler gc
Platform darwin/amd64
Reasons
Use wants to print shorted, more concise version output and fields such as Compiler or GoVersion can be not important for them.
Use cases
- Exclude Go related fields:
// excludedFields defines preset for fields that should be excluded in output. const excludedFields = version.FieldGoVersion | version.FieldCompiler | version.FieldPlatform printer := version.NewPrinter(version.WithExlcudedFields(excludedFields)) if err := printer.Print(os.Stdout); err != nil { log.Fatal(err) }
- Don't display empty(
"") and unset(N/A) fields:printer := version.NewPrinter(version.WithOmitUnset(excludedFields)) if err := printer.Print(os.Stdout); err != nil { log.Fatal(err) }
Implementation
- Use bit masks to set the enabled/disabled fields
const ( FieldVersion = 1 << iota FieldGitCommit FieldBuildDate FieldCommitDate FieldDirtyBuild FieldGoVersion FieldCompiler FieldPlatform typeRevMaxKey )
- Add popular presets
AllFieldsGoRuntimeFieldsVCSFields- VCS (Version control systems) related fields (git commit, date, dirty)
yurrriqKamsiy
Metadata
Metadata
Assignees
Labels
area/customizationEnables default behavior customizationEnables default behavior customization
Projects
Status
No status