Skip to content

Commit 61372c2

Browse files
authored
Merge pull request #45 from cpanato/follow
add WithFont function
2 parents 66f8709 + 3ddd8ad commit 61372c2

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

version/command.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff 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

version/command_test.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,23 @@ import (
2323
)
2424

2525
func 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

3341
func 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 {

0 commit comments

Comments
 (0)