mirror of
https://github.com/containers/podman.git
synced 2025-12-01 18:49:18 +08:00
`--format json` should not be the same as `--format {{json .}}`, the
later should actually run through the go template and thus create one
json object per entry instead of an json array.
Includes a vendor of c/common@main since it requires a fix from there as
well.
This matches docker compat.
Fixes #16436
Signed-off-by: Paul Holzinger <pholzing@redhat.com>
19 lines
502 B
Go
19 lines
502 B
Go
package report
|
|
|
|
import (
|
|
"regexp"
|
|
)
|
|
|
|
// Check for json, {{json }} and {{ json. }} which are not valid go template,
|
|
// {{json .}} is valid and thus not matched to let the template handle it like docker does.
|
|
var jsonRegex = regexp.MustCompile(`^\s*(json|{{\s*json\.?\s*}})\s*$`)
|
|
|
|
// JSONFormat test CLI --format string to be a JSON request
|
|
//
|
|
// if report.IsJSON(cmd.Flag("format").Value.String()) {
|
|
// ... process JSON and output
|
|
// }
|
|
func IsJSON(s string) bool {
|
|
return jsonRegex.MatchString(s)
|
|
}
|