Skip to content

Commit 0f2ae91

Browse files
committed
init: improve output
1 parent 237a367 commit 0f2ae91

4 files changed

Lines changed: 47 additions & 40 deletions

File tree

cmd/init.go

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -287,18 +287,6 @@ func (cmd *InitCmd) Run(f factory.Factory) error {
287287
}
288288

289289
if selectedDeploymentOption == DeployOptionHelm {
290-
hasOwnHelmChart := "Yes"
291-
helmChartAnswer, err := cmd.log.Question(&survey.QuestionOptions{
292-
Question: "Do you already have a Helm chart for this project?",
293-
Options: []string{
294-
"No",
295-
hasOwnHelmChart,
296-
},
297-
})
298-
if err != nil {
299-
return err
300-
}
301-
302290
if isQuickstart {
303291
quickstartYes := "Yes"
304292
quickstartAnswer, err := cmd.log.Question(&survey.QuestionOptions{
@@ -317,19 +305,33 @@ func (cmd *InitCmd) Run(f factory.Factory) error {
317305
}
318306
}
319307

320-
if helmChartAnswer == hasOwnHelmChart && !mustAddComponentChart {
321-
err = configureManager.AddHelmDeployment(imageName)
308+
if !mustAddComponentChart {
309+
hasOwnHelmChart := "Yes"
310+
helmChartAnswer, err := cmd.log.Question(&survey.QuestionOptions{
311+
Question: "Do you already have a Helm chart for this project?",
312+
Options: []string{
313+
"No",
314+
hasOwnHelmChart,
315+
},
316+
})
322317
if err != nil {
323-
if err.Error() != "" {
324-
cmd.log.WriteString(logrus.InfoLevel, "\n")
325-
cmd.log.Errorf("Error: %s", err.Error())
326-
}
318+
return err
319+
}
320+
321+
if helmChartAnswer == hasOwnHelmChart {
322+
err = configureManager.AddHelmDeployment(imageName)
323+
if err != nil {
324+
if err.Error() != "" {
325+
cmd.log.WriteString(logrus.InfoLevel, "\n")
326+
cmd.log.Errorf("Error: %s", err.Error())
327+
}
327328

328-
// Retry questions on error
329-
continue
329+
// Retry questions on error
330+
continue
331+
}
332+
} else {
333+
mustAddComponentChart = true
330334
}
331-
} else {
332-
mustAddComponentChart = true
333335
}
334336
} else if selectedDeploymentOption == DeployOptionKubectl || selectedDeploymentOption == DeployOptionKustomize {
335337
err = configureManager.AddKubectlDeployment(imageName, selectedDeploymentOption == DeployOptionKustomize)

pkg/devspace/configure/deployment.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,18 @@ import (
2222

2323
// AddKubectlDeployment adds a new kubectl deployment to the provided config
2424
func (m *manager) AddKubectlDeployment(deploymentName string, isKustomization bool) error {
25-
question := "Please enter the paths to your Kubernetes manifests (comma separated, glob patterns are allowed, e.g. 'manifests/**' or 'kube/pod.yaml')"
25+
question := "Please enter the paths to your Kubernetes manifests (comma separated, glob patterns are allowed, e.g. 'manifests/**' or 'kube/pod.yaml') [Enter to abort]"
2626
if isKustomization {
2727
question = "Please enter path to your Kustomization folder (e.g. ./kube/kustomization/)"
2828
}
2929

3030
manifests, err := m.log.Question(&survey.QuestionOptions{
3131
Question: question,
3232
ValidationFunc: func(value string) error {
33+
if value == "" {
34+
return nil
35+
}
36+
3337
if isKustomization {
3438
stat, err := os.Stat(path.Join(value, "kustomization.yaml"))
3539
if err == nil && !stat.IsDir() {
@@ -52,6 +56,10 @@ func (m *manager) AddKubectlDeployment(deploymentName string, isKustomization bo
5256
return err
5357
}
5458

59+
if manifests == "" {
60+
return fmt.Errorf("adding kubectl deployment aborted")
61+
}
62+
5563
splitted := strings.Split(manifests, ",")
5664
splittedPointer := []string{}
5765

pkg/devspace/configure/image.go

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -231,12 +231,13 @@ func (m *manager) addPullSecretConfig(dockerClient docker.Client, image string)
231231

232232
registryUsername := ""
233233
registryPassword := ""
234+
retry := false
234235

235236
m.log.WriteString(logrus.WarnLevel, "\n")
236237

237238
for {
238239
m.log.Info("Checking registry authentication for " + registryHostnamePrintable + "...")
239-
authConfig, err := dockerClient.Login(registryHostname, registryUsername, registryPassword, true, false, false)
240+
authConfig, err := dockerClient.Login(registryHostname, registryUsername, registryPassword, true, retry, retry)
240241
if err == nil && (authConfig.Username != "" || authConfig.Password != "") {
241242
registryUsername = authConfig.Username
242243

@@ -272,22 +273,9 @@ func (m *manager) addPullSecretConfig(dockerClient docker.Client, image string)
272273
// Check if docker is running
273274
_, runErr := command.Output(context.TODO(), "", "docker", "version")
274275

275-
retry := true
276-
277276
// If Docker is available, ask if we should retry registry login
278-
if runErr == nil {
279-
retryNo := "no"
280-
retryAnswer, err := m.log.Question(&survey.QuestionOptions{
281-
Question: "Do you want to retry logging into this registry?",
282-
Options: []string{"yes", retryNo},
283-
})
284-
if err != nil {
285-
return "", err
286-
}
287-
288-
if retryAnswer == retryNo {
289-
retry = false
290-
}
277+
if runErr == nil && registryUsername != "" {
278+
retry = true
291279
}
292280

293281
if !retry {

pkg/devspace/generator/language.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,15 +152,24 @@ func (cg *LanguageHandler) GetLanguage() (string, error) {
152152
if len(supportedLanguages) == 0 {
153153
language = langFallback
154154
} else {
155+
otherOption := "other"
156+
if language == langFallback {
157+
language = otherOption
158+
}
159+
155160
// Let the user select the language
156161
language, err = cg.log.Question(&survey.QuestionOptions{
157162
Question: "Select the programming language of this project",
158163
DefaultValue: language,
159-
Options: supportedLanguages,
164+
Options: append(supportedLanguages, otherOption),
160165
})
161166
if err != nil {
162167
return "", err
163168
}
169+
170+
if language == otherOption {
171+
language = langFallback
172+
}
164173
}
165174

166175
language = regexp.MustCompile(`^.*\((.*)\)$`).ReplaceAllString(language, "$1")

0 commit comments

Comments
 (0)