-
Notifications
You must be signed in to change notification settings - Fork 672
limactl shell: ask whether to start the instance if not running #2763
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -529,3 +529,55 @@ func startBashComplete(cmd *cobra.Command, _ []string, _ string) ([]string, cobr | |
compTmpl, _ := bashCompleteTemplateNames(cmd) | ||
return append(compInst, compTmpl...), cobra.ShellCompDirectiveDefault | ||
} | ||
|
||
// startInteractive starts the instance after a confirmation prompt. | ||
// | ||
// If newInst is set to true, this function creates the instance too. | ||
// | ||
// If mandatory is set to true, and the answer to the confirmation prompt is No, | ||
// the function returns an error that contains an instruction to start the instance manually. | ||
AkihiroSuda marked this conversation as resolved.
Show resolved
Hide resolved
|
||
func startInteractive(cmd *cobra.Command, instName string, newInst, mandatory bool) (bool, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is not clear what the |
||
flags := cmd.Flags() | ||
tty, err := flags.GetBool("tty") | ||
if err != nil { | ||
return false, err | ||
} | ||
errS := fmt.Sprintf("instance %q is stopped, run `limactl start %s` to start the instance", instName, instName) | ||
if newInst { | ||
errS = fmt.Sprintf("instance %q does not exist, run `limactl create %s` to create a new instance", instName, instName) | ||
} | ||
if !tty { | ||
if mandatory { | ||
return false, errors.New(errS) | ||
} | ||
return false, nil | ||
} | ||
logrus.Error(errS) | ||
|
||
message := fmt.Sprintf("Do you want to start the instance %q now?", instName) | ||
if newInst { | ||
message = fmt.Sprintf("Do you want to create and start the instance %q using the default template now?", instName) | ||
AkihiroSuda marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
ans, err := uiutil.Confirm(message, true) | ||
if err != nil { | ||
return false, err | ||
} | ||
if !ans { | ||
if mandatory { | ||
return ans, errors.New(errS) | ||
} | ||
return ans, nil | ||
} | ||
if newInst { | ||
rootCmd := cmd.Root() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
// The create command shows the template chooser UI, etc. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would have expected that the template would default to the instance name, if a template existed with that name. Otherwise it should show an error and only then default to $ l shell alpine
ERRO[0000] instance "alpine" does not exist, run `limactl create alpine` to create a new instance
? Do you want to create and start the instance "alpine" using the default template now? This should say "using the alpine template". There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree that the $ l shell alpine
ERRO[0000] instance "alpine" does not exist, run `limactl create alpine` to create a new instance
? Do you want to create and start the instance "alpine" using the default template now? No
FATA[0002] instance "alpine" does not exist, run `limactl create alpine` to create a new instance I think the The caller is already calling |
||
rootCmd.SetArgs([]string{"create", instName}) | ||
if err := rootCmd.Execute(); err != nil { | ||
return ans, err | ||
} | ||
} | ||
rootCmd := cmd.Root() | ||
// The start command reconciliates the networks, etc. | ||
rootCmd.SetArgs([]string{"start", instName}) | ||
return ans, rootCmd.Execute() | ||
} |
Uh oh!
There was an error while loading. Please reload this page.