This repository has been archived by the owner on Jun 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 364
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from datreeio/DAT-3181-add-dynamic-version
fix: add version command
- Loading branch information
Showing
6 changed files
with
59 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package version | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
func NewVersionCommand(cliVersion string) *cobra.Command { | ||
var versionCmd = &cobra.Command{ | ||
Use: "version", | ||
Short: "Print the version number", | ||
Long: "Print the version number", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
fmt.Println(cliVersion) | ||
}, | ||
} | ||
return versionCmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package version | ||
|
||
import ( | ||
"bytes" | ||
"io/ioutil" | ||
"testing" | ||
) | ||
|
||
func Test_ExecuteCommand(t *testing.T) { | ||
cmd := NewVersionCommand("1.2.3") | ||
b := bytes.NewBufferString("1.2.3") | ||
cmd.SetOut(b) | ||
cmd.Execute() | ||
out, err := ioutil.ReadAll(b) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
if string(out) != "1.2.3" { | ||
t.Fatalf("expected \"%s\" got \"%s\"", "1.2.3", string(out)) | ||
} | ||
} |