Run executes the command logic
(f factory.Factory)
| 105 | |
| 106 | // Run executes the command logic |
| 107 | func (cmd *InitCmd) Run(f factory.Factory) error { |
| 108 | // Check if config already exists |
| 109 | cmd.log = f.GetLog() |
| 110 | configLoader, err := f.NewConfigLoader("") |
| 111 | if err != nil { |
| 112 | return err |
| 113 | } |
| 114 | configExists := configLoader.Exists() |
| 115 | if configExists && !cmd.Reconfigure { |
| 116 | optionNo := "No" |
| 117 | cmd.log.WriteString(cmd.log.GetLevel(), "\n") |
| 118 | cmd.log.Warnf("%s already exists in this project", ansi.Color("devspace.yaml", "white+b")) |
| 119 | response, err := cmd.log.Question(&survey.QuestionOptions{ |
| 120 | Question: "Do you want to delete devspace.yaml and recreate it from scratch?", |
| 121 | Options: []string{optionNo, "Yes"}, |
| 122 | }) |
| 123 | if err != nil { |
| 124 | return err |
| 125 | } |
| 126 | |
| 127 | if response == optionNo { |
| 128 | return nil |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | // Delete config & overwrite config |
| 133 | os.RemoveAll(".devspace") |
| 134 | |
| 135 | // Delete configs path |
| 136 | os.Remove(constants.DefaultConfigsPath) |
| 137 | |
| 138 | // Delete config & overwrite config |
| 139 | os.Remove(constants.DefaultConfigPath) |
| 140 | |
| 141 | // Delete config & overwrite config |
| 142 | os.Remove(constants.DefaultVarsPath) |
| 143 | |
| 144 | // Execute plugin hook |
| 145 | err = hook.ExecuteHooks(nil, nil, "init") |
| 146 | if err != nil { |
| 147 | return err |
| 148 | } |
| 149 | |
| 150 | // Print DevSpace logo |
| 151 | log.PrintLogo() |
| 152 | |
| 153 | // Determine if we're initializing from scratch, or using docker-compose.yaml |
| 154 | dockerComposePath, generateFromDockerCompose, err := cmd.shouldGenerateFromDockerCompose() |
| 155 | if err != nil { |
| 156 | return err |
| 157 | } |
| 158 | |
| 159 | if generateFromDockerCompose { |
| 160 | err = cmd.initDockerCompose(f, dockerComposePath) |
| 161 | } else { |
| 162 | err = cmd.initDevspace(f, configLoader) |
| 163 | } |
| 164 | if err != nil { |
no test coverage detected