Skip to content

Commit 735a9d7

Browse files
committed
limactl start: add --list-templates flag
Signed-off-by: Akihiro Suda <[email protected]>
1 parent 0285c4e commit 735a9d7

File tree

2 files changed

+27
-8
lines changed

2 files changed

+27
-8
lines changed

README.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,16 +147,19 @@ Detailed usage:
147147
`--tty=false` disables the interactive prompt to open an editor.
148148

149149
```
150-
Create an instance "default" (if not created yet) from the default Ubuntu template, and start it:
150+
To create an instance "default" (if not created yet) from the default Ubuntu template, and start it:
151151
$ limactl start
152152
153-
Create an instance "default" from a template "docker":
153+
To create an instance "default" from a template "docker":
154154
$ limactl start --name=default template://docker
155155
156-
Create an instance "default" from a local file:
156+
To see the template list:
157+
$ limactl start --list-templates
158+
159+
To create an instance "default" from a local file:
157160
$ limactl start --name=default /usr/local/share/lima/examples/fedora.yaml
158161
159-
Create an instance "default" from a remote URL (use carefully, with a trustable source):
162+
To create an instance "default" from a remote URL (use carefully, with a trustable source):
160163
$ limactl start --name=default https://raw.githubusercontent.com/lima-vm/lima/master/examples/alpine.yaml
161164
```
162165
NOTE: `limactl start template://TEMPLATE` requires Lima v0.9.0 or later.

cmd/limactl/start.go

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,19 @@ func newStartCommand() *cobra.Command {
3232
var startCommand = &cobra.Command{
3333
Use: "start NAME|FILE.yaml|URL",
3434
Example: `
35-
Create an instance "default" (if not created yet) from the default Ubuntu template, and start it:
35+
To create an instance "default" (if not created yet) from the default Ubuntu template, and start it:
3636
$ limactl start
3737
38-
Create an instance "default" from a template "docker":
38+
To create an instance "default" from a template "docker":
3939
$ limactl start --name=default template://docker
4040
41-
Create an instance "default" from a local file:
41+
To see the template list:
42+
$ limactl start --list-templates
43+
44+
To create an instance "default" from a local file:
4245
$ limactl start --name=default /usr/local/share/lima/examples/fedora.yaml
4346
44-
Create an instance "default" from a remote URL (use carefully, with a trustable source):
47+
To create an instance "default" from a remote URL (use carefully, with a trustable source):
4548
$ limactl start --name=default https://raw.githubusercontent.com/lima-vm/lima/master/examples/alpine.yaml
4649
`,
4750
Short: "Start an instance of Lima",
@@ -51,6 +54,7 @@ $ limactl start --name=default https://raw.githubusercontent.com/lima-vm/lima/ma
5154
}
5255
startCommand.Flags().Bool("tty", isatty.IsTerminal(os.Stdout.Fd()), "enable TUI interactions such as opening an editor, defaults to true when stdout is a terminal")
5356
startCommand.Flags().String("name", "", "override the instance name")
57+
startCommand.Flags().Bool("list-templates", false, "list available templates and exit")
5458
return startCommand
5559
}
5660

@@ -424,6 +428,18 @@ func openEditor(name string, content []byte, hdr string) ([]byte, error) {
424428
}
425429

426430
func startAction(cmd *cobra.Command, args []string) error {
431+
if listTemplates, err := cmd.Flags().GetBool("list-templates"); err != nil {
432+
return err
433+
} else if listTemplates {
434+
if templates, err := listTemplateYAMLs(); err == nil {
435+
w := cmd.OutOrStdout()
436+
for _, f := range templates {
437+
fmt.Fprintln(w, f.Name)
438+
}
439+
return nil
440+
}
441+
}
442+
427443
inst, err := loadOrCreateInstance(cmd, args)
428444
if err != nil {
429445
return err

0 commit comments

Comments
 (0)