From 4e3b90c03c47b72573e269828faed7e3ba972b39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20R=C3=BCger?= Date: Thu, 12 Mar 2026 23:05:28 +0100 Subject: [PATCH] fix: route result output through Config.Output, not os.Stdout mark.Run and ProcessFile were writing directly to os.Stdout via fmt.Println, which is a surprising side-effect for library callers. Add Config.Output io.Writer for callers to provide their own sink. When nil the helper falls back to io.Discard, so library embedders that do not set Output receive no implicit stdout writes. The CLI layer sets Output: os.Stdout to preserve existing behaviour. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- mark.go | 19 +++++++++++++++++-- util/cli.go | 2 ++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/mark.go b/mark.go index 6a36f1a..e363ef2 100644 --- a/mark.go +++ b/mark.go @@ -5,6 +5,7 @@ import ( "crypto/sha1" "encoding/hex" "fmt" + "io" "os" "path/filepath" "regexp" @@ -67,6 +68,20 @@ type Config struct { Features []string ImageAlign string IncludePath string + + // Output is the writer used for result output (e.g. published page URLs, + // compiled HTML). If nil, output is discarded; the CLI sets this to + // os.Stdout. + Output io.Writer +} + +// output returns the configured writer, falling back to io.Discard so that +// library callers that do not set Output receive no implicit stdout writes. +func (c Config) output() io.Writer { + if c.Output != nil { + return c.Output + } + return io.Discard } // Run processes all files matching Config.Files and publishes them to Confluence. @@ -101,7 +116,7 @@ func Run(config Config) error { if target != nil { log.Infof(nil, "page successfully updated: %s", config.BaseURL+target.Links.Full) - fmt.Println(config.BaseURL + target.Links.Full) + fmt.Fprintln(config.output(), config.BaseURL+target.Links.Full) } } @@ -243,7 +258,7 @@ func ProcessFile(file string, api *confluence.API, config Config) (*confluence.P ImageAlign: imageAlign, } html, _ := markmd.CompileMarkdown(markdown, std, file, cfg) - fmt.Println(html) + fmt.Fprintln(config.output(), html) return nil, nil } diff --git a/util/cli.go b/util/cli.go index 42ab36d..4da26a8 100644 --- a/util/cli.go +++ b/util/cli.go @@ -83,6 +83,8 @@ func RunMark(ctx context.Context, cmd *cli.Command) error { Features: cmd.StringSlice("features"), ImageAlign: cmd.String("image-align"), IncludePath: cmd.String("include-path"), + + Output: os.Stdout, } return mark.Run(config)