From 2e39182582bf779e304fa6b7878c1428be938694 Mon Sep 17 00:00:00 2001 From: Wei Zhang Date: Wed, 10 Aug 2022 09:10:39 +0800 Subject: [PATCH] feat(CLI): :sparkles: add --force args for init to overwrite build.envd (#748) Signed-off-by: Wei Zhang --- pkg/app/init.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/pkg/app/init.go b/pkg/app/init.go index 1fc607dfb..5ec8e80f2 100644 --- a/pkg/app/init.go +++ b/pkg/app/init.go @@ -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, } @@ -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) } @@ -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")