File tree Expand file tree Collapse file tree 2 files changed +24
-4
lines changed
Expand file tree Collapse file tree 2 files changed +24
-4
lines changed Original file line number Diff line number Diff line change @@ -26,7 +26,19 @@ import (
2626// ```go
2727// rootCmd.AddCommand(version.Version())
2828// ```
29- func Version (fontName string ) * cobra.Command {
29+ func Version () * cobra.Command {
30+ return version ("" )
31+ }
32+
33+ // WithFont returns a cobra command to be added to another cobra command with a select font for ASCII, like:
34+ // ```go
35+ // rootCmd.AddCommand(version.WithFont("starwars"))
36+ // ```
37+ func WithFont (fontName string ) * cobra.Command {
38+ return version (fontName )
39+ }
40+
41+ func version (fontName string ) * cobra.Command {
3042 var outputJSON bool
3143 cmd := & cobra.Command {
3244 Use : "version" ,
@@ -37,7 +49,7 @@ func Version(fontName string) *cobra.Command {
3749 v .Description = cmd .Root ().Short
3850
3951 v .FontName = ""
40- if validFont := v .CheckFontName (fontName ); validFont {
52+ if fontName != "" && v .CheckFontName (fontName ) {
4153 v .FontName = fontName
4254 }
4355
Original file line number Diff line number Diff line change @@ -23,15 +23,23 @@ import (
2323)
2424
2525func TestVersion (t * testing.T ) {
26- v := version .Version ("fender" )
26+ v := version .Version ()
27+ err := v .Execute ()
28+ if err != nil {
29+ t .Errorf ("%v" , err )
30+ }
31+ }
32+
33+ func TestVersionWithFont (t * testing.T ) {
34+ v := version .WithFont ("fender" )
2735 err := v .Execute ()
2836 if err != nil {
2937 t .Errorf ("%v" , err )
3038 }
3139}
3240
3341func TestVersionJson (t * testing.T ) {
34- v := version .Version ("" )
42+ v := version .Version ()
3543 v .SetArgs ([]string {"--json" })
3644 err := v .Execute ()
3745 if err != nil {
You can’t perform that action at this time.
0 commit comments