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

feat: setting version dynamically #83

Merged
merged 2 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/cmdtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func CallCmd(
projectsClient *projects.MockClient,
args []string,
) ([]byte, error) {
rootCmd, err := NewRootCommand(flagsClient, membersClient, projectsClient)
rootCmd, err := NewRootCommand(flagsClient, membersClient, projectsClient, "test")
require.NoError(t, err)
b := bytes.NewBufferString("")
rootCmd.SetOut(b)
Expand Down
8 changes: 4 additions & 4 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ import (
"ldcli/internal/projects"
)

func NewRootCommand(flagsClient flags.Client, membersClient members.Client, projectsClient projects.Client) (*cobra.Command, error) {
func NewRootCommand(flagsClient flags.Client, membersClient members.Client, projectsClient projects.Client, version string) (*cobra.Command, error) {
cmd := &cobra.Command{
Use: "ldcli",
Short: "LaunchDarkly CLI",
Long: "LaunchDarkly CLI to control your feature flags",
Version: "0.0.1", // TODO: set this based on release or use `cmd.SetVersionTemplate(s string)`
Version: version,

// Handle errors differently based on type.
// We don't want to show the usage if the user has the right structure but invalid data such as
Expand Down Expand Up @@ -78,8 +78,8 @@ func NewRootCommand(flagsClient flags.Client, membersClient members.Client, proj
return cmd, nil
}

func Execute() {
rootCmd, err := NewRootCommand(flags.NewClient(), members.NewClient(), projects.NewClient())
func Execute(version string) {
rootCmd, err := NewRootCommand(flags.NewClient(), members.NewClient(), projects.NewClient(), version)
if err != nil {
log.Fatal(err)
}
Expand Down
24 changes: 24 additions & 0 deletions cmd/root_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package cmd

import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"ldcli/internal/flags"
)

func TestCreate(t *testing.T) {
t.Run("with valid flags prints version", func(t *testing.T) {
client := flags.MockClient{}
args := []string{
"--version",
}

output, err := CallCmd(t, &client, nil, nil, args)

require.NoError(t, err)
assert.Contains(t, string(output), `ldcli version test`)
})
}
6 changes: 5 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ package main

import "ldcli/cmd"

var (
version = "dev"
)

func main() {
cmd.Execute()
cmd.Execute(version)
}
Loading