mirror of
https://github.com/yarlson/lnk.git
synced 2025-09-01 18:02:34 +02:00
feat(output): implement configurable color and emoji output
Add new output formatting system with flags for color and emoji control: - Introduce OutputConfig and Writer structs for flexible output handling - Add --colors and --emoji/--no-emoji global flags - Refactor commands to use new Writer for consistent formatting - Separate error content from presentation for better flexibility
This commit is contained in:
45
cmd/pull.go
45
cmd/pull.go
@@ -1,7 +1,10 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/yarlson/lnk/internal/core"
|
||||
)
|
||||
|
||||
@@ -14,8 +17,8 @@ func newPullCmd() *cobra.Command {
|
||||
SilenceErrors: true,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
host, _ := cmd.Flags().GetString("host")
|
||||
|
||||
lnk := core.NewLnk(core.WithHost(host))
|
||||
w := GetWriter(cmd)
|
||||
|
||||
restored, err := lnk.Pull()
|
||||
if err != nil {
|
||||
@@ -23,31 +26,47 @@ func newPullCmd() *cobra.Command {
|
||||
}
|
||||
|
||||
if len(restored) > 0 {
|
||||
var successMsg string
|
||||
if host != "" {
|
||||
printf(cmd, "⬇️ \033[1;32mSuccessfully pulled changes (host: %s)\033[0m\n", host)
|
||||
successMsg = fmt.Sprintf("Successfully pulled changes (host: %s)", host)
|
||||
} else {
|
||||
printf(cmd, "⬇️ \033[1;32mSuccessfully pulled changes\033[0m\n")
|
||||
successMsg = "Successfully pulled changes"
|
||||
}
|
||||
printf(cmd, " 🔗 Restored \033[1m%d symlink", len(restored))
|
||||
|
||||
symlinkText := fmt.Sprintf("Restored %d symlink", len(restored))
|
||||
if len(restored) > 1 {
|
||||
printf(cmd, "s")
|
||||
symlinkText += "s"
|
||||
}
|
||||
printf(cmd, "\033[0m:\n")
|
||||
symlinkText += ":"
|
||||
|
||||
w.Writeln(Message{Text: successMsg, Emoji: "⬇️", Color: ColorBrightGreen, Bold: true}).
|
||||
WriteString(" ").
|
||||
Writeln(Link(symlinkText))
|
||||
|
||||
for _, file := range restored {
|
||||
printf(cmd, " ✨ \033[36m%s\033[0m\n", file)
|
||||
w.WriteString(" ").
|
||||
Writeln(Sparkles(file))
|
||||
}
|
||||
printf(cmd, "\n 🎉 Your dotfiles are synced and ready!\n")
|
||||
|
||||
w.WritelnString("").
|
||||
WriteString(" ").
|
||||
Writeln(Message{Text: "Your dotfiles are synced and ready!", Emoji: "🎉"})
|
||||
} else {
|
||||
var successMsg string
|
||||
if host != "" {
|
||||
printf(cmd, "⬇️ \033[1;32mSuccessfully pulled changes (host: %s)\033[0m\n", host)
|
||||
successMsg = fmt.Sprintf("Successfully pulled changes (host: %s)", host)
|
||||
} else {
|
||||
printf(cmd, "⬇️ \033[1;32mSuccessfully pulled changes\033[0m\n")
|
||||
successMsg = "Successfully pulled changes"
|
||||
}
|
||||
printf(cmd, " ✅ All symlinks already in place\n")
|
||||
printf(cmd, " 🎉 Everything is up to date!\n")
|
||||
|
||||
w.Writeln(Message{Text: successMsg, Emoji: "⬇️", Color: ColorBrightGreen, Bold: true}).
|
||||
WriteString(" ").
|
||||
Writeln(Success("All symlinks already in place")).
|
||||
WriteString(" ").
|
||||
Writeln(Message{Text: "Everything is up to date!", Emoji: "🎉"})
|
||||
}
|
||||
|
||||
return nil
|
||||
return w.Err()
|
||||
},
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user