Skip to content

Commit

Permalink
Merge pull request #45 from cpanato/follow
Browse files Browse the repository at this point in the history
add WithFont function
  • Loading branch information
k8s-ci-robot committed Mar 28, 2022
2 parents 66f8709 + 3ddd8ad commit 61372c2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
16 changes: 14 additions & 2 deletions version/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,19 @@ import (
// ```go
// rootCmd.AddCommand(version.Version())
// ```
func Version(fontName string) *cobra.Command {
func Version() *cobra.Command {
return version("")
}

// WithFont returns a cobra command to be added to another cobra command with a select font for ASCII, like:
// ```go
// rootCmd.AddCommand(version.WithFont("starwars"))
// ```
func WithFont(fontName string) *cobra.Command {
return version(fontName)
}

func version(fontName string) *cobra.Command {
var outputJSON bool
cmd := &cobra.Command{
Use: "version",
Expand All @@ -37,7 +49,7 @@ func Version(fontName string) *cobra.Command {
v.Description = cmd.Root().Short

v.FontName = ""
if validFont := v.CheckFontName(fontName); validFont {
if fontName != "" && v.CheckFontName(fontName) {
v.FontName = fontName
}

Expand Down
12 changes: 10 additions & 2 deletions version/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,23 @@ import (
)

func TestVersion(t *testing.T) {
v := version.Version("fender")
v := version.Version()
err := v.Execute()
if err != nil {
t.Errorf("%v", err)
}
}

func TestVersionWithFont(t *testing.T) {
v := version.WithFont("fender")
err := v.Execute()
if err != nil {
t.Errorf("%v", err)
}
}

func TestVersionJson(t *testing.T) {
v := version.Version("")
v := version.Version()
v.SetArgs([]string{"--json"})
err := v.Execute()
if err != nil {
Expand Down

0 comments on commit 61372c2

Please sign in to comment.