Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ var startCmdArgs struct {
Foreground bool
SaveConfig bool
LegacyCPU int // for backward compatibility
Template bool
}
}

Expand Down Expand Up @@ -171,6 +172,7 @@ func init() {
startCmd.Flags().BoolVarP(&startCmdArgs.Flags.Foreground, "foreground", "f", false, "Keep colima in the foreground")
startCmd.Flags().StringVar(&startCmdArgs.Hostname, "hostname", "", "custom hostname for the virtual machine")
startCmd.Flags().StringVarP(&startCmdArgs.DiskImage, "disk-image", "i", "", "file path to a custom disk image")
startCmd.Flags().BoolVar(&startCmdArgs.Flags.Template, "template", false, "use the template file for initial configuration")

// retain cpu flag for backward compatibility
startCmd.Flags().IntVar(&startCmdArgs.Flags.LegacyCPU, "cpu", defaultCPU, "number of CPUs")
Expand Down Expand Up @@ -410,13 +412,21 @@ func prepareConfig(cmd *cobra.Command) {

// if there is no existing settings
if current.Empty() {
// attempt template
template, err := configmanager.LoadFrom(templateFile())
if err != nil {
// use default config if there is no template or existing settings
templateUsed := false

// attempt template if enabled
if startCmdArgs.Flags.Template {
template, err := configmanager.LoadFrom(templateFile())
if err == nil {
current = template
templateUsed = true
}
}

if !templateUsed {
// use default config if there is no template or template is disabled
return
}
current = template
}

// set missing defaults in the current config
Expand Down