From d8ad60ce8a7debd76f558d0e8fa6eaf5a21621b9 Mon Sep 17 00:00:00 2001 From: Snider Date: Fri, 20 Mar 2026 12:19:11 +0000 Subject: [PATCH] =?UTF-8?q?refactor:=20Printl=20helper=20in=20utils.go=20?= =?UTF-8?q?=E2=80=94=20Cli.Print=20delegates=20to=20it?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit core.Printl(w, format, args...) writes a formatted line to any writer, defaulting to os.Stdout. Cli.Print() delegates to Printl. Co-Authored-By: Virgil --- pkg/core/cli.go | 7 +------ pkg/core/utils.go | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/pkg/core/cli.go b/pkg/core/cli.go index 08d1ef8..6cdfb8d 100644 --- a/pkg/core/cli.go +++ b/pkg/core/cli.go @@ -14,7 +14,6 @@ package core import ( - "fmt" "io" "os" "strings" @@ -31,11 +30,7 @@ type Cli struct { // // c.Cli().Print("hello %s", "world") func (cl *Cli) Print(format string, args ...any) { - w := cl.output - if w == nil { - w = os.Stdout - } - fmt.Fprintf(w, format+"\n", args...) + Printl(cl.output, format, args...) } // SetOutput sets the CLI output writer. diff --git a/pkg/core/utils.go b/pkg/core/utils.go index 8b059b1..05eb803 100644 --- a/pkg/core/utils.go +++ b/pkg/core/utils.go @@ -5,10 +5,24 @@ package core import ( + "fmt" + "io" + "os" "strings" "unicode/utf8" ) +// Printl writes a formatted line to a writer, defaulting to os.Stdout. +// +// core.Printl(nil, "hello %s", "world") // → stdout +// core.Printl(w, "port: %d", 8080) // → w +func Printl(w io.Writer, format string, args ...any) { + if w == nil { + w = os.Stdout + } + fmt.Fprintf(w, format+"\n", args...) +} + // FilterArgs removes empty strings and Go test runner flags from an argument list. // // clean := core.FilterArgs(os.Args[1:])