diff --git a/version/command.go b/version/command.go index 7eee9c7..c1034e9 100644 --- a/version/command.go +++ b/version/command.go @@ -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", @@ -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 } diff --git a/version/command_test.go b/version/command_test.go index bd205de..f58984c 100644 --- a/version/command_test.go +++ b/version/command_test.go @@ -23,7 +23,15 @@ 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) @@ -31,7 +39,7 @@ func TestVersion(t *testing.T) { } func TestVersionJson(t *testing.T) { - v := version.Version("") + v := version.Version() v.SetArgs([]string{"--json"}) err := v.Execute() if err != nil {