Skip to content

Commit 8248413

Browse files
committed
limactl: relax limactl start --name=foo restriction
Previously `limactl start --name=foo` without explicit template:// was not supported ```console $ limactl start --name foo FATA[0000] instance name "default" and CLI flag --name="foo" cannot be specified together ``` Signed-off-by: Akihiro Suda <[email protected]>
1 parent e486db9 commit 8248413

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

cmd/limactl/start.go

Lines changed: 13 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,11 +152,17 @@ 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
}
@@ -169,7 +173,7 @@ func loadOrCreateInstance(cmd *cobra.Command, args []string) (*store.Instance, e
169173
if !errors.Is(err, os.ErrNotExist) {
170174
return nil, err
171175
}
172-
if st.instName != DefaultInstanceName {
176+
if arg != "" && arg != DefaultInstanceName {
173177
logrus.Infof("Creating an instance %q from template://default (Not from template://%s)", st.instName, st.instName)
174178
logrus.Warnf("This form is deprecated. Use `limactl start --name=%s template://default` instead", st.instName)
175179
}

0 commit comments

Comments
 (0)