@@ -3,6 +3,7 @@ package main
3
3
import (
4
4
"errors"
5
5
"fmt"
6
+ "io"
6
7
"net/http"
7
8
"os"
8
9
"path/filepath"
@@ -43,6 +44,9 @@ $ limactl start --name=default /usr/local/share/lima/examples/fedora.yaml
43
44
44
45
To create an instance "default" from a remote URL (use carefully, with a trustable source):
45
46
$ limactl start --name=default https://raw.githubusercontent.com/lima-vm/lima/master/examples/alpine.yaml
47
+
48
+ To create an instance "local" from a template passed to stdin (--name parameter is required):
49
+ $ cat template.yaml | limactl start --name=local -
46
50
` ,
47
51
Short : "Start an instance of Lima" ,
48
52
Args : cobra .MaximumNArgs (1 ),
@@ -67,6 +71,13 @@ func loadOrCreateInstance(cmd *cobra.Command, args []string) (*store.Instance, e
67
71
st = & creatorState {}
68
72
err error
69
73
)
74
+
75
+ // Create an instance, with menu TUI when TTY is available
76
+ tty , err := cmd .Flags ().GetBool ("tty" )
77
+ if err != nil {
78
+ return nil , err
79
+ }
80
+
70
81
st .instName , err = cmd .Flags ().GetString ("name" )
71
82
if err != nil {
72
83
return nil , err
@@ -136,6 +147,20 @@ func loadOrCreateInstance(cmd *cobra.Command, args []string) (*store.Instance, e
136
147
if err != nil {
137
148
return nil , err
138
149
}
150
+ } else if arg == "-" {
151
+ if st .instName == "" {
152
+ return nil , errors .New ("must pass instance name with --name when reading template from stdin" )
153
+ }
154
+ st .yBytes , err = io .ReadAll (os .Stdin )
155
+ if err != nil && err != io .EOF {
156
+ return nil , fmt .Errorf ("unexpected error reading stdin: %w" , err )
157
+ }
158
+ // see if the tty was set explicitly or not
159
+ ttySet := cmd .Flags ().Changed ("tty" )
160
+ if ttySet && tty {
161
+ return nil , errors .New ("cannot use --tty=true and read template from stdin together" )
162
+ }
163
+ tty = false
139
164
} else {
140
165
if arg == "" {
141
166
if st .instName == "" {
@@ -173,11 +198,6 @@ func loadOrCreateInstance(cmd *cobra.Command, args []string) (*store.Instance, e
173
198
}
174
199
}
175
200
176
- // Create an instance, with menu TUI when TTY is available
177
- tty , err := cmd .Flags ().GetBool ("tty" )
178
- if err != nil {
179
- return nil , err
180
- }
181
201
if tty {
182
202
var err error
183
203
st , err = chooseNextCreatorState (st )
0 commit comments