From 91b8823a7969f3a310815905fe0a28bbe957e998 Mon Sep 17 00:00:00 2001 From: Alberto Ricart Date: Wed, 3 May 2023 11:22:12 -0500 Subject: [PATCH] [BREAKING] this change directly writes action reports to stdout Fixes #580 --- cmd/action.go | 13 ++++++++++--- cmd/generatenkey.go | 6 ++++-- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/cmd/action.go b/cmd/action.go index a12c4efc..96ce2d54 100644 --- a/cmd/action.go +++ b/cmd/action.go @@ -1,5 +1,5 @@ /* - * Copyright 2018 The NATS Authors + * Copyright 2018-2023 The NATS Authors * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -143,15 +143,22 @@ func run(ctx ActionCtx, action interface{}) error { rs, err := e.Run(ctx) if rs != nil { - ctx.CurrentCmd().Println(rs.Message()) + if err := Write("--", []byte(rs.Message())); err != nil { + return err + } sum, ok := rs.(store.Summarizer) if ok { m, err := sum.Summary() if err != nil { return err } + if len(m) > 0 && !strings.HasSuffix(m, "\n") { + m = fmt.Sprintf("%s\n", m) + } if m != "" { - ctx.CurrentCmd().Println(strings.TrimSuffix(m, "\n")) + if err := Write("--", []byte(m)); err != nil { + return err + } } } } diff --git a/cmd/generatenkey.go b/cmd/generatenkey.go index ae753c7c..b6f94951 100644 --- a/cmd/generatenkey.go +++ b/cmd/generatenkey.go @@ -1,5 +1,5 @@ /* - * Copyright 2018-2020 The NATS Authors + * Copyright 2018-2023 The NATS Authors * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -152,7 +152,9 @@ func (p *GenerateNKeysParam) Run(ctx ActionCtx) (store.Status, error) { return nil, err } } - ctx.CurrentCmd().Println(j.String(p.store)) + if err := Write("--", []byte(j.String(p.store))); err != nil { + return nil, err + } } } return nil, nil