enbas/internal/executor/version.go
Dan Anglin 55b93c6586
fix(breaking): update project structure
Move all executors to the internal folder package. This PR also comes
with additional breaking changes.

Changes:

- refactor: move all executors to the internal/executor package.
- refactor: update naming patterns for constants, variables, custom
  types, etc.
- fix(breaking): renamed the update command to edit.
- fix(breaking): update the flags for the switch command to make it
  more generic.
- fix(breaking): renamed the show-account-relationship flag to
  show-relationship.
- fix: update the print message from the whoami command.
2024-05-23 18:06:49 +01:00

55 lines
1.1 KiB
Go

package executor
import (
"flag"
"fmt"
"os"
"strings"
)
type VersionExecutor struct {
*flag.FlagSet
showFullVersion bool
binaryVersion string
buildTime string
goVersion string
gitCommit string
}
func NewVersionExecutor(name, summary, binaryVersion, buildTime, goVersion, gitCommit string) *VersionExecutor {
command := VersionExecutor{
FlagSet: flag.NewFlagSet(name, flag.ExitOnError),
binaryVersion: binaryVersion,
buildTime: buildTime,
goVersion: goVersion,
gitCommit: gitCommit,
showFullVersion: false,
}
command.BoolVar(&command.showFullVersion, "full", false, "prints the full build information")
command.Usage = commandUsageFunc(name, summary, command.FlagSet)
return &command
}
func (c *VersionExecutor) Execute() error {
var builder strings.Builder
if c.showFullVersion {
fmt.Fprintf(
&builder,
"Enbas\n Version: %s\n Git commit: %s\n Go version: %s\n Build date: %s\n",
c.binaryVersion,
c.gitCommit,
c.goVersion,
c.buildTime,
)
} else {
fmt.Fprintln(&builder, c.binaryVersion)
}
fmt.Fprint(os.Stdout, builder.String())
return nil
}