Allow docker context ls —formatter {{json.}} to not delegate to Moby and include context type in the json

Signed-off-by: Guillaume Tardif <guillaume.tardif@docker.com>
This commit is contained in:
Guillaume Tardif 2020-10-05 15:14:05 +02:00
parent 0cea91c555
commit a1bb2d5abe
4 changed files with 19 additions and 3 deletions

View file

@ -69,7 +69,8 @@ func runList(cmd *cobra.Command, opts lsOpts) error {
if err != nil {
return err
}
if opts.format != "" && opts.format != formatter.JSON && opts.format != formatter.PRETTY {
format := strings.ToLower(strings.ReplaceAll(opts.format, " ", ""))
if format != "" && format != formatter.JSON && format != formatter.PRETTY && format != formatter.TemplateJSON {
mobycli.Exec(cmd.Root())
return nil
}
@ -93,7 +94,7 @@ func runList(cmd *cobra.Command, opts lsOpts) error {
return nil
}
if opts.json {
if opts.json || format == formatter.JSON || format == formatter.TemplateJSON {
opts.format = formatter.JSON
}