Skip to content

Commit

Permalink
add build and version to the info tool
Browse files Browse the repository at this point in the history
  • Loading branch information
rusq committed Oct 11, 2024
1 parent eb3f578 commit f8e8770
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 14 deletions.
12 changes: 12 additions & 0 deletions cmd/slackdump/internal/cfg/cfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,20 @@ var (
NoUserCache bool

Log logger.Interface

Version BuildInfo // version propagated by main package.
)

type BuildInfo struct {
Version string `json:"version"`
Commit string `json:"commit"`
Date string `json:"date"`
}

func (b BuildInfo) String() string {
return fmt.Sprintf("Slackdump %s (commit: %s) built on: %s", b.Version, b.Commit, b.Date)
}

type FlagMask uint16

const (
Expand Down
12 changes: 7 additions & 5 deletions cmd/slackdump/internal/diag/info/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,12 @@ import (
)

type SysInfo struct {
OS OSInfo `json:"os"`
Workspace Workspace `json:"workspace"`
Playwright PwInfo `json:"playwright"`
Rod RodInfo `json:"rod"`
EzLogin EZLogin `json:"ez_login"`
Slackdump SlackdumpInfo `json:"slackdump"`
OS OSInfo `json:"os"`
Workspace Workspace `json:"workspace"`
Playwright PwInfo `json:"playwright"`
Rod RodInfo `json:"rod"`
EzLogin EZLogin `json:"ez_login"`
}

// Collect collects system information, replacing user's name in paths with
Expand All @@ -71,6 +72,7 @@ func collect(fn func(string) string) *SysInfo {
si.Rod.collect,
si.EzLogin.collect,
si.OS.collect,
si.Slackdump.collect,
}
for _, c := range collectors {
c(fn)
Expand Down
17 changes: 17 additions & 0 deletions cmd/slackdump/internal/diag/info/slackdump.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package info

import (
"runtime"

"github.com/rusq/slackdump/v3/cmd/slackdump/internal/cfg"
)

type SlackdumpInfo struct {
Build cfg.BuildInfo `json:"build"`
GoVersion string `json:"go_version"`
}

func (inf *SlackdumpInfo) collect(PathReplFunc) {
inf.Build = cfg.Version
inf.GoVersion = runtime.Version()
}
6 changes: 2 additions & 4 deletions cmd/slackdump/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ func initLog(filename string, verbose bool) (*dlog.Logger, error) {
}

// secrets defines the names of the supported secret files that we load our
// secrets from. Inexperienced windows users might have bad experience trying
// secrets from. Inexperienced Windows users might have bad experience trying
// to create .env file with the notepad as it will battle for having the
// "txt" extension. Let it have it.
var secretFiles = []string{".env", ".env.txt", "secrets.txt"}
Expand All @@ -310,9 +310,7 @@ const (
)

func whatDo() (choice, error) {
fmt.Println()
printVersion()
fmt.Println()
fmt.Print("\n" + cfg.Version.String() + "\n")

var ans choice
err := huh.NewSelect[choice]().
Expand Down
15 changes: 10 additions & 5 deletions cmd/slackdump/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"

"github.com/rusq/slackdump/v3/cmd/slackdump/internal/cfg"
"github.com/rusq/slackdump/v3/cmd/slackdump/internal/golang/base"
)

Expand All @@ -13,6 +14,14 @@ var (
date = "unknown"
)

func init() {
cfg.Version = cfg.BuildInfo{
Version: version,
Commit: commit,
Date: date,
}
}

var CmdVersion = &base.Command{
UsageLine: "version",
Short: "print version and exit",
Expand All @@ -27,10 +36,6 @@ And by the way, version is: ` + version + `, commit: ` + commit + `, built on `
}

func versionRun(context.Context, *base.Command, []string) error {
printVersion()
fmt.Println(cfg.Version)
return nil
}

func printVersion() {
fmt.Printf("Slackdump %s (commit: %s) built on: %s\n", version, commit, date)
}

0 comments on commit f8e8770

Please sign in to comment.