|
| 1 | +/* |
| 2 | +Copyright 2025 The Doctl Authors All rights reserved. |
| 3 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +you may not use this file except in compliance with the License. |
| 5 | +You may obtain a copy of the License at |
| 6 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 7 | +Unless required by applicable law or agreed to in writing, software |
| 8 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 9 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 10 | +See the License for the specific language governing permissions and |
| 11 | +limitations under the License. |
| 12 | +*/ |
| 13 | + |
| 14 | +package displayers |
| 15 | + |
| 16 | +import ( |
| 17 | + "io" |
| 18 | + |
| 19 | + "github.com/digitalocean/doctl/do" |
| 20 | +) |
| 21 | + |
| 22 | +type MicroDroplet struct { |
| 23 | + MicroDroplets do.MicroDroplets |
| 24 | +} |
| 25 | + |
| 26 | +var _ Displayable = &MicroDroplet{} |
| 27 | + |
| 28 | +func (m *MicroDroplet) JSON(out io.Writer) error { |
| 29 | + return writeJSON(m.MicroDroplets, out) |
| 30 | +} |
| 31 | + |
| 32 | +func (m *MicroDroplet) Cols() []string { |
| 33 | + return []string{ |
| 34 | + "ID", "Name", "Region", "State", "Size", "Networking", "Image", "Endpoint", "Created", |
| 35 | + } |
| 36 | +} |
| 37 | + |
| 38 | +func (m *MicroDroplet) ColMap() map[string]string { |
| 39 | + return map[string]string{ |
| 40 | + "ID": "ID", |
| 41 | + "Name": "Name", |
| 42 | + "Region": "Region", |
| 43 | + "State": "State", |
| 44 | + "Size": "Size", |
| 45 | + "Networking": "Networking", |
| 46 | + "Image": "Image", |
| 47 | + "Endpoint": "Endpoint", |
| 48 | + "Created": "Created At", |
| 49 | + } |
| 50 | +} |
| 51 | + |
| 52 | +func (m *MicroDroplet) KV() []map[string]any { |
| 53 | + out := make([]map[string]any, 0, len(m.MicroDroplets)) |
| 54 | + for _, md := range m.MicroDroplets { |
| 55 | + out = append(out, map[string]any{ |
| 56 | + "ID": md.ID, |
| 57 | + "Name": md.Name, |
| 58 | + "Region": md.Region, |
| 59 | + "State": string(md.State), |
| 60 | + "Size": md.Size, |
| 61 | + "Networking": string(md.Networking), |
| 62 | + "Image": md.Image, |
| 63 | + "Endpoint": md.Endpoint, |
| 64 | + "Created": md.Created, |
| 65 | + }) |
| 66 | + } |
| 67 | + return out |
| 68 | +} |
| 69 | + |
| 70 | +type MicroDropletCheckpoint struct { |
| 71 | + Checkpoints do.MicroDropletCheckpoints |
| 72 | +} |
| 73 | + |
| 74 | +var _ Displayable = &MicroDropletCheckpoint{} |
| 75 | + |
| 76 | +func (c *MicroDropletCheckpoint) JSON(out io.Writer) error { |
| 77 | + return writeJSON(c.Checkpoints, out) |
| 78 | +} |
| 79 | + |
| 80 | +func (c *MicroDropletCheckpoint) Cols() []string { |
| 81 | + return []string{ |
| 82 | + "ID", "MicroDropletID", "Name", "Status", "MemoryBytes", "DiskBytes", "Created", |
| 83 | + } |
| 84 | +} |
| 85 | + |
| 86 | +func (c *MicroDropletCheckpoint) ColMap() map[string]string { |
| 87 | + return map[string]string{ |
| 88 | + "ID": "ID", |
| 89 | + "MicroDropletID": "MicroDroplet ID", |
| 90 | + "Name": "Name", |
| 91 | + "Status": "Status", |
| 92 | + "MemoryBytes": "Memory Bytes", |
| 93 | + "DiskBytes": "Disk Bytes", |
| 94 | + "Created": "Created At", |
| 95 | + } |
| 96 | +} |
| 97 | + |
| 98 | +func (c *MicroDropletCheckpoint) KV() []map[string]any { |
| 99 | + out := make([]map[string]any, 0, len(c.Checkpoints)) |
| 100 | + for _, cp := range c.Checkpoints { |
| 101 | + out = append(out, map[string]any{ |
| 102 | + "ID": cp.ID, |
| 103 | + "MicroDropletID": cp.MicroDropletID, |
| 104 | + "Name": cp.Name, |
| 105 | + "Status": string(cp.Status), |
| 106 | + "MemoryBytes": cp.MemoryBytes, |
| 107 | + "DiskBytes": cp.DiskBytes, |
| 108 | + "Created": cp.Created, |
| 109 | + }) |
| 110 | + } |
| 111 | + return out |
| 112 | +} |
0 commit comments