From 6cddbfebda0ba2ee52d4faa87657749423eceed4 Mon Sep 17 00:00:00 2001 From: Martin Treml Date: Wed, 10 Jul 2024 11:06:23 +0200 Subject: [PATCH] Command to print the current version of the binary Part of #207 --- cmd/eval-dev-quality/cmd/command.go | 1 + cmd/eval-dev-quality/cmd/version.go | 31 ++++++++++++++++++++++++ cmd/eval-dev-quality/cmd/version_test.go | 19 +++++++++++++++ 3 files changed, 51 insertions(+) create mode 100644 cmd/eval-dev-quality/cmd/version.go create mode 100644 cmd/eval-dev-quality/cmd/version_test.go diff --git a/cmd/eval-dev-quality/cmd/command.go b/cmd/eval-dev-quality/cmd/command.go index 74808743f..dd0cb2791 100644 --- a/cmd/eval-dev-quality/cmd/command.go +++ b/cmd/eval-dev-quality/cmd/command.go @@ -9,6 +9,7 @@ import ( type Command struct { Evaluate `command:"evaluate" description:"Run an evaluation, by default with all defined models, repositories and tasks."` InstallTools `command:"install-tools" description:"Checks and installs all tools required for the evaluation benchmark."` + Version `command:"version" description:"Display the version information of the binary."` } // Execute executes the root command. diff --git a/cmd/eval-dev-quality/cmd/version.go b/cmd/eval-dev-quality/cmd/version.go new file mode 100644 index 000000000..0989c00a4 --- /dev/null +++ b/cmd/eval-dev-quality/cmd/version.go @@ -0,0 +1,31 @@ +package cmd + +import ( + "github.com/symflower/eval-dev-quality/evaluate" + "github.com/symflower/eval-dev-quality/log" +) + +// Version defines the "version" command. +type Version struct { + // logger holds the logger of the command. + logger *log.Logger +} + +var _ SetLogger = (*Version)(nil) + +// SetLogger sets the logger of the command. +func (command *Version) SetLogger(logger *log.Logger) { + command.logger = logger +} + +// Execute executes the command. +func (command *Version) Execute(args []string) (err error) { + revision := evaluate.Revision + if evaluate.Revision == "" { + revision = "development" + } + command.logger.SetFlags(0) // Remove the timestamp and everything from the log output while still being able to test it. + command.logger.Printf("eval-dev-quality version %s - revision %s", evaluate.Version, revision) + + return nil +} diff --git a/cmd/eval-dev-quality/cmd/version_test.go b/cmd/eval-dev-quality/cmd/version_test.go new file mode 100644 index 000000000..eba566437 --- /dev/null +++ b/cmd/eval-dev-quality/cmd/version_test.go @@ -0,0 +1,19 @@ +package cmd + +import ( + "fmt" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/symflower/eval-dev-quality/evaluate" + "github.com/symflower/eval-dev-quality/log" +) + +func TestVersionExecute(t *testing.T) { + logOutput, logger := log.Buffer() + + Execute(logger, []string{"version"}) + + expected := fmt.Sprintf("eval-dev-quality version %s - revision %s", evaluate.Version, "development") + assert.Contains(t, logOutput.String(), expected) +}