1/*
2Copyright 2018 The Doctl Authors All rights reserved.
3Licensed under the Apache License, Version 2.0 (the "License");
4you may not use this file except in compliance with the License.
5You may obtain a copy of the License at
6    http://www.apache.org/licenses/LICENSE-2.0
7Unless required by applicable law or agreed to in writing, software
8distributed under the License is distributed on an "AS IS" BASIS,
9WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10See the License for the specific language governing permissions and
11limitations under the License.
12*/
13
14package displayers
15
16import (
17	"io"
18
19	"github.com/digitalocean/doctl/do"
20)
21
22type Kernel struct {
23	Kernels do.Kernels
24}
25
26var _ Displayable = &Kernel{}
27
28func (ke *Kernel) JSON(out io.Writer) error {
29	return writeJSON(ke.Kernels, out)
30}
31
32func (ke *Kernel) Cols() []string {
33	return []string{
34		"ID", "Name", "Version",
35	}
36}
37
38func (ke *Kernel) ColMap() map[string]string {
39	return map[string]string{
40		"ID": "ID", "Name": "Name", "Version": "Version",
41	}
42}
43
44func (ke *Kernel) KV() []map[string]interface{} {
45	out := make([]map[string]interface{}, 0, len(ke.Kernels))
46
47	for _, k := range ke.Kernels {
48		o := map[string]interface{}{
49			"ID": k.ID, "Name": k.Name, "Version": k.Version,
50		}
51
52		out = append(out, o)
53	}
54
55	return out
56}
57