Append newline to "-o json" for validate/summary/run (#2326)

## Changes
- Insert newline after rendering indented JSON in bundle
validate/summary/run.
- This prevents "No newline at end of file" message in various cases,
for example when switching between recording raw output of the command
to output processed by jq, since jq does add a newline or when running
diff in acceptance tests.

## Tests
Manually running validate:

```
~/work/dabs_cuj_brickfood % ../cli/cli-main bundle validate -o json | tail -n 2  # without change
Error: root_path must start with '~/' or contain the current username to ensure uniqueness when using 'mode: development'

  }
}%
~/work/dabs_cuj_brickfood % ../cli/cli bundle validate -o json | tail -n 2  # with change
Error: root_path must start with '~/' or contain the current username to ensure uniqueness when using 'mode: development'

  }
}
~/work/dabs_cuj_brickfood %
```

Via #2316 -- see cleaner output there.
This commit is contained in:
Denis Bilenko 2025-02-10 14:00:49 +01:00 committed by GitHub
parent 047691dd91
commit d282f33a22
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 6 additions and 1 deletions

View File

@ -23,6 +23,7 @@ Error: failed during request visitor: parse "https://${var.host}": invalid chara
"host": "${var.host}" "host": "${var.host}"
} }
} }
Exit code: 1 Exit code: 1
>>> errcode [CLI] bundle validate >>> errcode [CLI] bundle validate

View File

@ -173,6 +173,7 @@ task or a Python wheel task, the second example applies.
if err != nil { if err != nil {
return err return err
} }
_, _ = cmd.OutOrStdout().Write([]byte{'\n'})
default: default:
return fmt.Errorf("unknown output type %s", root.OutputType(cmd)) return fmt.Errorf("unknown output type %s", root.OutputType(cmd))
} }

View File

@ -74,6 +74,7 @@ func newSummaryCommand() *cobra.Command {
return err return err
} }
_, _ = cmd.OutOrStdout().Write(buf) _, _ = cmd.OutOrStdout().Write(buf)
_, _ = cmd.OutOrStdout().Write([]byte{'\n'})
default: default:
return fmt.Errorf("unknown output type %s", root.OutputType(cmd)) return fmt.Errorf("unknown output type %s", root.OutputType(cmd))
} }

View File

@ -20,7 +20,9 @@ func renderJsonOutput(cmd *cobra.Command, b *bundle.Bundle) error {
if err != nil { if err != nil {
return err return err
} }
_, _ = cmd.OutOrStdout().Write(buf) out := cmd.OutOrStdout()
_, _ = out.Write(buf)
_, _ = out.Write([]byte{'\n'})
return nil return nil
} }