Skip to content

Commit 2b13585

Browse files
authored
Merge pull request #789 from AkihiroSuda/relax-limactl-start-name
limactl: relax `limactl start --name=foo` restriction
2 parents 8eccbeb + 9c871f6 commit 2b13585

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

cmd/limactl/start.go

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,8 @@ func readDefaultTemplate() ([]byte, error) {
7575
}
7676

7777
func loadOrCreateInstance(cmd *cobra.Command, args []string) (*store.Instance, error) {
78-
var arg string
79-
if len(args) == 0 {
80-
arg = DefaultInstanceName
81-
} else {
78+
var arg string // can be empty
79+
if len(args) > 0 {
8280
arg = args[0]
8381
}
8482

@@ -154,22 +152,31 @@ func loadOrCreateInstance(cmd *cobra.Command, args []string) (*store.Instance, e
154152
return nil, err
155153
}
156154
} else {
157-
logrus.Debugf("interpreting argument %q as an instance name", arg)
158-
if st.instName != "" && st.instName != arg {
159-
return nil, fmt.Errorf("instance name %q and CLI flag --name=%q cannot be specified together", arg, st.instName)
155+
if arg == "" {
156+
if st.instName == "" {
157+
st.instName = DefaultInstanceName
158+
}
159+
} else {
160+
logrus.Debugf("interpreting argument %q as an instance name", arg)
161+
if st.instName != "" && st.instName != arg {
162+
return nil, fmt.Errorf("instance name %q and CLI flag --name=%q cannot be specified together", arg, st.instName)
163+
}
164+
st.instName = arg
160165
}
161-
st.instName = arg
162166
if err := identifiers.Validate(st.instName); err != nil {
163167
return nil, fmt.Errorf("argument must be either an instance name, a YAML file path, or a URL, got %q: %w", st.instName, err)
164168
}
165169
if inst, err := store.Inspect(st.instName); err == nil {
166170
logrus.Infof("Using the existing instance %q", st.instName)
171+
if arg == "" {
172+
logrus.Infof("Hint: To create another instance, run the following command: limactl start --name=NAME template://default")
173+
}
167174
return inst, nil
168175
} else {
169176
if !errors.Is(err, os.ErrNotExist) {
170177
return nil, err
171178
}
172-
if st.instName != DefaultInstanceName {
179+
if arg != "" && arg != DefaultInstanceName {
173180
logrus.Infof("Creating an instance %q from template://default (Not from template://%s)", st.instName, st.instName)
174181
logrus.Warnf("This form is deprecated. Use `limactl start --name=%s template://default` instead", st.instName)
175182
}

0 commit comments

Comments
 (0)