Skip to content

Commit 02934b9

Browse files
authored
Merge pull request #3990 from jandubois/list-yaml
Make `limactl ls --format yaml` use the same schema as the json output
2 parents 562d5c9 + b9c1684 commit 02934b9

File tree

3 files changed

+27
-7
lines changed

3 files changed

+27
-7
lines changed

cmd/limactl/list.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,14 @@ func fieldNames() []string {
3131
f := t.Field(i)
3232
if f.Anonymous {
3333
for j := range f.Type.NumField() {
34-
names = append(names, f.Type.Field(j).Name)
34+
if tag := f.Tag.Get("lima"); tag != "deprecated" {
35+
names = append(names, f.Type.Field(j).Name)
36+
}
3537
}
3638
} else {
37-
names = append(names, t.Field(i).Name)
39+
if tag := f.Tag.Get("lima"); tag != "deprecated" {
40+
names = append(names, t.Field(i).Name)
41+
}
3842
}
3943
}
4044
return names

pkg/limainfo/limainfo.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,15 @@ import (
77
"context"
88
"errors"
99
"io/fs"
10+
"path/filepath"
11+
"runtime"
1012

1113
"github.com/sirupsen/logrus"
1214

1315
"github.com/lima-vm/lima/v2/pkg/envutil"
1416
"github.com/lima-vm/lima/v2/pkg/limatype"
1517
"github.com/lima-vm/lima/v2/pkg/limatype/dirnames"
18+
"github.com/lima-vm/lima/v2/pkg/limatype/filenames"
1619
"github.com/lima-vm/lima/v2/pkg/limayaml"
1720
"github.com/lima-vm/lima/v2/pkg/registry"
1821
"github.com/lima-vm/lima/v2/pkg/templatestore"
@@ -29,6 +32,9 @@ type LimaInfo struct {
2932
VMTypesEx map[string]DriverExt `json:"vmTypesEx"` // since Lima v2.0.0
3033
GuestAgents map[limatype.Arch]GuestAgent `json:"guestAgents"` // since Lima v1.1.0
3134
ShellEnvBlock []string `json:"shellEnvBlock"`
35+
HostOS string `json:"hostOS"` // since Lima v2.0.0
36+
HostArch string `json:"hostArch"` // since Lima v2.0.0
37+
IdentityFile string `json:"identityFile"` // since Lima v2.0.0
3238
}
3339

3440
type DriverExt struct {
@@ -72,6 +78,8 @@ func New(ctx context.Context) (*LimaInfo, error) {
7278
VMTypesEx: vmTypesEx,
7379
GuestAgents: make(map[limatype.Arch]GuestAgent),
7480
ShellEnvBlock: envutil.GetDefaultBlockList(),
81+
HostOS: runtime.GOOS,
82+
HostArch: limatype.NewArch(runtime.GOARCH),
7583
}
7684
info.Templates, err = templatestore.Templates()
7785
if err != nil {
@@ -81,6 +89,11 @@ func New(ctx context.Context) (*LimaInfo, error) {
8189
if err != nil {
8290
return nil, err
8391
}
92+
configDir, err := dirnames.LimaConfigDir()
93+
if err != nil {
94+
return nil, err
95+
}
96+
info.IdentityFile = filepath.Join(configDir, filenames.UserPrivateKey)
8497
for _, arch := range limatype.ArchTypes {
8598
bin, err := usrlocalsharelima.GuestAgentBinary(limatype.LINUX, arch)
8699
if err != nil {

pkg/store/instance.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -225,11 +225,14 @@ func ReadPIDFile(path string) (int, error) {
225225
}
226226

227227
type FormatData struct {
228-
limatype.Instance
229-
HostOS string
230-
HostArch string
231-
LimaHome string
232-
IdentityFile string
228+
limatype.Instance `yaml:",inline"`
229+
230+
// Using these host attributes is deprecated; they will be removed in Lima 3.0
231+
// The values are available from `limactl info` as hostOS, hostArch, limaHome, and identifyFile.
232+
HostOS string `json:"HostOS" yaml:"HostOS" lima:"deprecated"`
233+
HostArch string `json:"HostArch" yaml:"HostArch" lima:"deprecated"`
234+
LimaHome string `json:"LimaHome" yaml:"LimaHome" lima:"deprecated"`
235+
IdentityFile string `json:"IdentityFile" yaml:"IdentityFile" lima:"deprecated"`
233236
}
234237

235238
var FormatHelp = "\n" +

0 commit comments

Comments
 (0)