Skip to content

Commit

Permalink
feat: friendly prompt when exec envd init (#1562)
Browse files Browse the repository at this point in the history
feat: when running `envd init`, check if build.envd exists firstly

re #1559

Signed-off-by: hui <13019718290@163.com>
  • Loading branch information
rrain7 authored Apr 18, 2023
1 parent c0010cc commit bc0eaf8
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions pkg/app/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,22 @@ func isCondaEnvFile(file string) bool {
}

func initCommand(clicontext *cli.Context) error {
lang := strings.ToLower(clicontext.String("lang"))
buildContext, err := filepath.Abs(clicontext.Path("path"))
force := clicontext.Bool("force")
if err != nil {
return err
}

filePath := filepath.Join(buildContext, "build.envd")
exists, err := fileutil.FileExists(filePath)
if err != nil {
return err
}
if exists && !force {
return errors.Errorf("build.envd already exists, use --force to overwrite it.\nOr you can run the command `envd up` to set up a new environment.")
}

lang := strings.ToLower(clicontext.String("lang"))
if !isValidLang(lang) {
startQuestion(LanguageChoice)
if len(selectionMap[LabelLanguage]) > 0 {
Expand All @@ -139,15 +148,6 @@ func initCommand(clicontext *cli.Context) error {
"init", telemetry.AddField("duration", time.Since(start).Seconds()))
}(time.Now())

filePath := filepath.Join(buildContext, "build.envd")
exists, err := fileutil.FileExists(filePath)
if err != nil {
return err
}
if exists && !force {
return errors.Errorf("build.envd already exists, use --force to overwrite it")
}

if lang == "python" {
err = InitPythonEnv(buildContext)
if err != nil {
Expand Down

0 comments on commit bc0eaf8

Please sign in to comment.