Skip to content

Commit 7454862

Browse files
committed
Add printer.go from main.go
1 parent 9627750 commit 7454862

3 files changed

Lines changed: 36 additions & 11 deletions

File tree

cmd/mdefaults/main.go

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"github.com/fumiya-kume/mdefaults/internal/filesystem"
1313
pullop "github.com/fumiya-kume/mdefaults/internal/operation/pull"
1414
pushop "github.com/fumiya-kume/mdefaults/internal/operation/push"
15+
"github.com/fumiya-kume/mdefaults/internal/printer"
1516
)
1617

1718
var (
@@ -75,7 +76,7 @@ func run() int {
7576
fmt.Println("macOS Configuration:")
7677
macOSConfigs, err := pullop.Pull(configs)
7778
if err != nil {
78-
printError("Failed to pull configurations")
79+
printer.PrintError("Failed to pull configurations")
7980
return 1
8081
}
8182
printConfigs(macOSConfigs)
@@ -94,7 +95,7 @@ func run() int {
9495
}
9596
}
9697

97-
printSuccess("Configurations pulled successfully")
98+
printer.PrintSuccess("Configurations pulled successfully")
9899
if err := config.WriteConfigFile(fs, macOSConfigs); err != nil {
99100
log.Printf("Failed to write config file: %v", err)
100101
return 1
@@ -127,17 +128,9 @@ func printConfigs(configs []config.Config) {
127128
}
128129
}
129130

130-
func printError(message string) {
131-
color.Red("Error: %s", message)
132-
}
133-
134-
func printSuccess(message string) {
135-
color.Green("Success: %s", message)
136-
}
137-
138131
func handlePush(configs []config.Config) int {
139132
pushop.Push(configs)
140-
printSuccess("Configurations pushed successfully")
133+
printer.PrintSuccess("Configurations pushed successfully")
141134
return 0
142135
}
143136

internal/printer/printer.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package printer
2+
3+
import (
4+
"github.com/fatih/color"
5+
)
6+
7+
// PrintError prints an error message in red color
8+
func PrintError(message string) {
9+
color.Red("Error: %s", message)
10+
}
11+
12+
// PrintSuccess prints a success message in green color
13+
func PrintSuccess(message string) {
14+
color.Green("Success: %s", message)
15+
}

internal/printer/printer_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package printer
2+
3+
import (
4+
"testing"
5+
)
6+
7+
func TestPrintSuccess(t *testing.T) {
8+
// This test simply verifies that the function doesn't panic
9+
// We can't easily capture colored output in tests
10+
PrintSuccess("Test success message")
11+
}
12+
13+
func TestPrintError(t *testing.T) {
14+
// This test simply verifies that the function doesn't panic
15+
// We can't easily capture colored output in tests
16+
PrintError("Test error message")
17+
}

0 commit comments

Comments
 (0)