-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Sergiy Kulanov <[email protected]>
- Loading branch information
Showing
7 changed files
with
78 additions
and
6 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,30 @@ | ||
package version | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
const ( | ||
// Version is the current version of the CLI | ||
devVersion = "dev" | ||
) | ||
|
||
var ( | ||
cliVersion = devVersion | ||
) | ||
|
||
// Command returns the version command | ||
func Command() *cobra.Command { | ||
return &cobra.Command{ | ||
Use: "version", | ||
Short: "Prints version information", | ||
Annotations: map[string]string{ | ||
"commandType": "utility", | ||
}, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
fmt.Fprintf(cmd.OutOrStdout(), "%s\n", cliVersion) | ||
}, | ||
} | ||
} |
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,24 @@ | ||
package version | ||
|
||
import ( | ||
"bytes" | ||
"testing" | ||
) | ||
|
||
func TestVersionCommand(t *testing.T) { | ||
cmd := Command() | ||
|
||
// Create a Buffer to capture the output. | ||
out := new(bytes.Buffer) | ||
cmd.SetOut(out) | ||
|
||
// Execute the command. | ||
if err := cmd.Execute(); err != nil { | ||
t.Errorf("Failed to execute command: %v", err) | ||
} | ||
|
||
// Assert that the command is valid. | ||
if cmd == nil || cmd.Name() != "version" { | ||
t.Errorf("Command is not valid: %v", cmd) | ||
} | ||
} |
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