refactor: Printl helper in utils.go — Cli.Print delegates to it
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 <virgil@lethean.io>
This commit is contained in:
parent
6687db76f3
commit
d8ad60ce8a
2 changed files with 15 additions and 6 deletions
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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:])
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue