Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to exclude a given version fields and omit empty #12

Open
mszostok opened this issue Jul 30, 2022 · 4 comments
Open

Add option to exclude a given version fields and omit empty #12

mszostok opened this issue Jul 30, 2022 · 4 comments
Labels
area/customization Enables default behavior customization
Milestone

Comments

@mszostok
Copy link
Owner

mszostok commented Jul 30, 2022

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
    • AllFields
    • GoRuntimeFields
    • VCSFields - VCS (Version control systems) related fields (git commit, date, dirty)
@mszostok mszostok added the enhancement New feature or request label Jul 30, 2022
@mszostok mszostok changed the title Add option to disable exclude a given version field and omit empty Add option to exclude a given version fields and omit empty Jul 30, 2022
@mszostok mszostok added area/customization Enables default behavior customization and removed enhancement New feature or request labels Jul 30, 2022
@mszostok mszostok added this to the v1.2.0 milestone Sep 30, 2022
@Kamsiy
Copy link
Contributor

Kamsiy commented May 3, 2023

Is anyone working on this? is this available to pickup?

@mszostok
Copy link
Owner Author

mszostok commented May 5, 2023

Hi @Kamsiy

It's still available 👍 Ping me if you would like to discuss that in more details, I am happy to assist 👍

@mszostok mszostok modified the milestones: v1.2.0, v1.3.0 May 6, 2023
@Kamsiy
Copy link
Contributor

Kamsiy commented May 10, 2023

Hey @mszostok 👋 ,

In this feature, should the Get function in the version package also exclude fields?

version/version.go

Lines 115 to 133 in a69cf43

func Get() *Info {
collectOnce.Do(collectFromBuildInfo)
dirty, _ := strconv.ParseBool(dirtyBuild)
if name == unknownProperty {
name = os.Args[0]
}
return &Info{
Meta: Meta{CLIName: name},
Version: version,
GitCommit: commit,
BuildDate: buildDate,
CommitDate: commitDate,
DirtyBuild: dirty,
GoVersion: runtime.Version(),
Compiler: runtime.Compiler,
Platform: fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH),
}
}

@Kamsiy
Copy link
Contributor

Kamsiy commented May 12, 2023

Also for the common presets, Please can I get some feedback on my current mapping

GoRuntimeFields - FieldGoVersion | FieldCompiler | FieldPlatform
VCSFields - FieldGitCommit | FieldBuildDate | FieldCommitDate | FieldDirtyBuild
AllFields - VCSFields | GoRuntimeFields | FieldVersion | FieldMeta | FieldExtraFields

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/customization Enables default behavior customization
Projects
Status: No status
Development

No branches or pull requests

2 participants