Skip to content

Commit

Permalink
feat(CLI): ✨ add --force args for init to overwrite build.envd (#748)
Browse files Browse the repository at this point in the history
Signed-off-by: Wei Zhang <kweizh@gmail.com>
  • Loading branch information
zwpaper committed Aug 10, 2022
1 parent d241898 commit 2e39182
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions pkg/app/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,16 @@ var CommandInit = &cli.Command{
Flags: []cli.Flag{
&cli.StringFlag{
Name: "lang",
Usage: "language usage. Support Python, R",
Usage: "language usage. Support Python, R, Julia",
Aliases: []string{"l"},
Required: true,
},
&cli.BoolFlag{
Name: "force",
Usage: "overwrite the build.envd if existed",
Aliases: []string{"f"},
Required: false,
},
},
Action: initCommand,
}
Expand All @@ -57,6 +63,7 @@ func isValidLang(lang string) bool {

func initCommand(clicontext *cli.Context) error {
lang := strings.ToLower(clicontext.String("lang"))
force := clicontext.Bool("force")
if !isValidLang(lang) {
return errors.Errorf("invalid language %s", lang)
}
Expand All @@ -65,8 +72,8 @@ func initCommand(clicontext *cli.Context) error {
if err != nil {
return err
}
if exists {
return errors.Errorf("build.envd already exists")
if exists && !force {
return errors.Errorf("build.envd already exists, use --force to overwrite it")
}

buildEnvdContent, err := templatef.ReadFile("template/" + lang + ".envd")
Expand Down

0 comments on commit 2e39182

Please sign in to comment.