Skip to content

Commit

Permalink
[BREAKING] this change directly writes action reports to stdout
Browse files Browse the repository at this point in the history
Fixes #580
  • Loading branch information
aricart committed May 3, 2023
1 parent 25fcf21 commit 91b8823
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
13 changes: 10 additions & 3 deletions cmd/action.go
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
}
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions cmd/generatenkey.go
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 91b8823

Please sign in to comment.