Skip to content
This repository was archived by the owner on Mar 27, 2024. It is now read-only.

Commit 1cf9c86

Browse files
author
Priya Wadhwa
committed
Added readme
1 parent d49adc7 commit 1cf9c86

File tree

2 files changed

+38
-3
lines changed

2 files changed

+38
-3
lines changed

README.md

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,42 @@ type MultiVersionInfo struct {
239239
}
240240
```
241241

242+
## User Customized Output
243+
Users can customize the format of the output of diffs with the`--format` flag. The flag takes a Go template string, which specifies the format the diff should be output in. This template string uses the structs described above, depending on the differ used, to format output. The default template strings container-diff uses can be found [here](https://github.com/GoogleCloudPlatform/container-diff/blob/master/util/template_utils.go).
244+
245+
An example using the pip package analyzer is shown below, in which only package names are printed (some are repeated because of version differences).
246+
247+
```shell
248+
$ container-diff analyze gcr.io/google-appengine/python:latest --type=pip --format='
249+
-----{{.AnalyzeType}}-----
250+
Packages found in {{.Image}}:{{if not .Analysis}} None{{else}}
251+
{{range .Analysis}}{{"\n"}}{{.Name}}{{end}}
252+
{{end}}
253+
'
254+
Retrieving image gcr.io/google-appengine/python:latest from source Cloud Registry
255+
Retrieving analyses
256+
257+
-----Pip-----
258+
Packages found in gcr.io/google-appengine/python:latest:
259+
260+
chardet
261+
colorama
262+
html5lib
263+
mercurial
264+
pip
265+
pip
266+
pip
267+
requests
268+
setuptools
269+
setuptools
270+
setuptools
271+
six
272+
urllib3
273+
virtualenv
274+
wheel
275+
wheel
276+
```
277+
242278
## Known issues
243279

244280
To run container-diff using image IDs, docker must be installed.
@@ -422,7 +458,7 @@ If using existing package tools, you should create the appropriate structs (e.g.
422458
```go
423459
type Result interface {
424460
OutputStruct() interface{}
425-
OutputText(resultType string) error
461+
OutputText(resultType string, format string) error
426462
}
427463
```
428464

util/format_utils.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,13 @@ func TemplateOutputFromFormat(diff interface{}, templateType string, format stri
8787
funcs := template.FuncMap{"join": strings.Join}
8888
tmpl, err := template.New("tmpl").Funcs(funcs).Parse(format)
8989
if err != nil {
90-
logrus.Info("User specified format resulted in error, printing default output.")
90+
logrus.Warningf("User specified format resulted in error, printing default output.")
9191
logrus.Error(err)
9292
return TemplateOutput(diff, templateType)
9393
}
9494
w := tabwriter.NewWriter(os.Stdout, 8, 8, 8, ' ', 0)
9595
err = tmpl.Execute(w, diff)
9696
if err != nil {
97-
logrus.Error(err)
9897
return err
9998
}
10099
w.Flush()

0 commit comments

Comments
 (0)