| 1 | |
| 2 | |
| 3 | |
| 4 | package main |
| 5 | |
| 6 | import ( |
| 7 | "github.com/spf13/cobra" |
| 8 | ) |
| 9 | |
| 10 | func newAutostartCommand() *cobra.Command { |
| 11 | autostartCommand := &cobra.Command{ |
| 12 | Use: "autostart", |
| 13 | Short: "Manage automatic startup of Lima instances", |
| 14 | GroupID: advancedCommand, |
| 15 | } |
| 16 | autostartCommand.AddCommand(newAutostartEnableCommand(), newAutostartDisableCommand()) |
| 17 | return autostartCommand |
| 18 | } |
| 19 | |
| 20 | func newAutostartEnableCommand() *cobra.Command { |
| 21 | cmd := &cobra.Command{ |
| 22 | Use: "enable INSTANCE", |
| 23 | Short: "Register an instance to start automatically", |
| 24 | Args: WrapArgsError(cobra.ExactArgs(1)), |
| 25 | RunE: autostartEnableAction, |
| 26 | ValidArgsFunction: autostartComplete, |
| 27 | } |
| 28 | flags := cmd.Flags() |
| 29 | flags.String( |
| 30 | "condition", "login", |
| 31 | "When to start the instance: \"login\" (user session) or \"boot\" (system boot, macOS only)", |
| 32 | ) |
| 33 | flags.String( |
| 34 | "user", "", |
| 35 | "macOS username to run the instance as when --condition=boot (default: $USER)", |
| 36 | ) |
| 37 | flags.Bool( |
| 38 | "keep-alive", true, |
| 39 | "Restart the instance automatically if the host agent exits unexpectedly", |
| 40 | ) |
| 41 | return cmd |
| 42 | } |
| 43 | |
| 44 | func newAutostartDisableCommand() *cobra.Command { |
| 45 | return &cobra.Command{ |
| 46 | Use: "disable INSTANCE", |
| 47 | Short: "Unregister an instance from automatic startup", |
| 48 | Args: WrapArgsError(cobra.ExactArgs(1)), |
| 49 | RunE: autostartDisableAction, |
| 50 | ValidArgsFunction: autostartComplete, |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | func autostartComplete(cmd *cobra.Command, _ []string, _ string) ([]string, cobra.ShellCompDirective) { |
| 55 | return bashCompleteInstanceNames(cmd) |
| 56 | } |