Skip to content

Commit 87f5a06

Browse files
authored
Merge pull request #1643 from AkihiroSuda/limactl-create
limactl: add `limactl create` command
2 parents 0b65a14 + 65f0000 commit 87f5a06

File tree

13 files changed

+121
-47
lines changed

13 files changed

+121
-47
lines changed

.github/workflows/release.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ jobs:
7777
7878
## Usage
7979
\`\`\`console
80+
[macOS]$ limactl create
8081
[macOS]$ limactl start
8182
...
8283
INFO[0029] READY. Run \`lima\` to open the shell.

cmd/apptainer.lima

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ set -eu
33
: "${LIMA_INSTANCE:=apptainer}"
44

55
if [ "$(limactl ls -q "$LIMA_INSTANCE" 2>/dev/null)" != "$LIMA_INSTANCE" ]; then
6-
echo "instance \"$LIMA_INSTANCE\" does not exist, run \`limactl start --name=$LIMA_INSTANCE template://apptainer\` to create a new instance" >&2
6+
echo "instance \"$LIMA_INSTANCE\" does not exist, run \`limactl create --name=$LIMA_INSTANCE template://apptainer\` to create a new instance" >&2
77
exit 1
88
fi
99
export LIMA_INSTANCE

cmd/docker.lima

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ set -eu
44
: "${DOCKER:=docker}"
55

66
if [ "$(limactl ls -q "$LIMA_INSTANCE" 2>/dev/null)" != "$LIMA_INSTANCE" ]; then
7-
echo "instance \"$LIMA_INSTANCE\" does not exist, run \`limactl start --name=$LIMA_INSTANCE template://docker\` to create a new instance" >&2
7+
echo "instance \"$LIMA_INSTANCE\" does not exist, run \`limactl create --name=$LIMA_INSTANCE template://docker\` to create a new instance" >&2
88
exit 1
99
fi
1010
DOCKER=$(command -v "$DOCKER" || true)

cmd/kubectl.lima

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ if [ -z "$LIMA_INSTANCE" ]; then
99
elif [ "$(limactl ls -f '{{.Status}}' k8s 2>/dev/null)" = "Running" ]; then
1010
LIMA_INSTANCE=k8s
1111
else
12-
echo "No k3s or k8s running instances found. Either start one with" >&2
13-
echo "limactl start --name=k3s template://k3s" >&2
14-
echo "limactl start --name=k8s template://k8s" >&2
12+
echo "No k3s or k8s running instances found. Either create one with" >&2
13+
echo "limactl create --name=k3s template://k3s" >&2
14+
echo "limactl create --name=k8s template://k8s" >&2
1515
echo "or set LIMA_INSTANCE to the name of your Kubernetes instance" >&2
1616
exit 1
1717
fi
1818
elif [ "$(limactl ls -q "$LIMA_INSTANCE" 2>/dev/null)" != "$LIMA_INSTANCE" ]; then
19-
echo "instance \"$LIMA_INSTANCE\" does not exist, run \`limactl start --name=$LIMA_INSTANCE\` to create a new instance" >&2
19+
echo "instance \"$LIMA_INSTANCE\" does not exist, run \`limactl create --name=$LIMA_INSTANCE\` to create a new instance" >&2
2020
exit 1
2121
fi
2222
KUBECTL=$(command -v "$KUBECTL" || true)

cmd/limactl/completion.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
"github.com/lima-vm/lima/pkg/store"
5+
"github.com/lima-vm/lima/pkg/templatestore"
56
"github.com/spf13/cobra"
67
)
78

@@ -12,3 +13,13 @@ func bashCompleteInstanceNames(_ *cobra.Command) ([]string, cobra.ShellCompDirec
1213
}
1314
return instances, cobra.ShellCompDirectiveNoFileComp
1415
}
16+
17+
func bashCompleteTemplateNames(_ *cobra.Command) ([]string, cobra.ShellCompDirective) {
18+
var comp []string
19+
if templates, err := templatestore.Templates(); err == nil {
20+
for _, f := range templates {
21+
comp = append(comp, "template://"+f.Name)
22+
}
23+
}
24+
return comp, cobra.ShellCompDirectiveDefault
25+
}

cmd/limactl/copy.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func copyAction(cmd *cobra.Command, args []string) error {
7878
inst, err := store.Inspect(instName)
7979
if err != nil {
8080
if errors.Is(err, os.ErrNotExist) {
81-
return fmt.Errorf("instance %q does not exist, run `limactl start %s` to create a new instance", instName, instName)
81+
return fmt.Errorf("instance %q does not exist, run `limactl create %s` to create a new instance", instName, instName)
8282
}
8383
return err
8484
}

cmd/limactl/list.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ func listAction(cmd *cobra.Command, args []string) error {
119119
return err
120120
}
121121
if len(allinstances) == 0 {
122-
logrus.Warn("No instance found. Run `limactl start` to create an instance.")
122+
logrus.Warn("No instance found. Run `limactl create` to create an instance.")
123123
return nil
124124
}
125125

cmd/limactl/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ func newApp() *cobra.Command {
9494
return nil
9595
}
9696
rootCmd.AddCommand(
97+
newCreateCommand(),
9798
newStartCommand(),
9899
newStopCommand(),
99100
newShellCommand(),

cmd/limactl/shell.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func shellAction(cmd *cobra.Command, args []string) error {
6161

6262
if len(args) >= 2 {
6363
switch args[1] {
64-
case "start", "delete", "shell":
64+
case "create", "start", "delete", "shell":
6565
// `lima start` (alias of `limactl $LIMA_INSTANCE start`) is probably a typo of `limactl start`
6666
logrus.Warnf("Perhaps you meant `limactl %s`?", strings.Join(args[1:], " "))
6767
}
@@ -70,7 +70,7 @@ func shellAction(cmd *cobra.Command, args []string) error {
7070
inst, err := store.Inspect(instName)
7171
if err != nil {
7272
if errors.Is(err, os.ErrNotExist) {
73-
return fmt.Errorf("instance %q does not exist, run `limactl start %s` to create a new instance", instName, instName)
73+
return fmt.Errorf("instance %q does not exist, run `limactl create %s` to create a new instance", instName, instName)
7474
}
7575
return err
7676
}

cmd/limactl/show_ssh.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func showSSHAction(cmd *cobra.Command, args []string) error {
6868
inst, err := store.Inspect(instName)
6969
if err != nil {
7070
if errors.Is(err, os.ErrNotExist) {
71-
return fmt.Errorf("instance %q does not exist, run `limactl start %s` to create a new instance", instName, instName)
71+
return fmt.Errorf("instance %q does not exist, run `limactl create %s` to create a new instance", instName, instName)
7272
}
7373
return err
7474
}

0 commit comments

Comments
 (0)