Skip to content

Commit

Permalink
Command to print the current version of the binary
Browse files Browse the repository at this point in the history
Part of #207
  • Loading branch information
Munsio committed Jul 10, 2024
1 parent 53052fe commit 6cddbfe
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmd/eval-dev-quality/cmd/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
31 changes: 31 additions & 0 deletions cmd/eval-dev-quality/cmd/version.go
Original file line number Diff line number Diff line change
@@ -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
}
19 changes: 19 additions & 0 deletions cmd/eval-dev-quality/cmd/version_test.go
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit 6cddbfe

Please sign in to comment.