From b9b195b70f66b353fe0366ae5b38014f6d49da99 Mon Sep 17 00:00:00 2001 From: Sam Alba Date: Thu, 1 Apr 2021 10:49:17 -0700 Subject: [PATCH] cmd/new: implemented optional arg to specify name, forbid usage of -d option Signed-off-by: Sam Alba --- cmd/dagger/cmd/new.go | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/cmd/dagger/cmd/new.go b/cmd/dagger/cmd/new.go index 5368f495..8b21d3f1 100644 --- a/cmd/dagger/cmd/new.go +++ b/cmd/dagger/cmd/new.go @@ -17,7 +17,7 @@ import ( var newCmd = &cobra.Command{ Use: "new", Short: "Create a new deployment", - Args: cobra.NoArgs, + Args: cobra.MaximumNArgs(1), PreRun: func(cmd *cobra.Command, args []string) { // Fix Viper bug for duplicate flags: // https://github.com/spf13/viper/issues/233 @@ -33,8 +33,21 @@ var newCmd = &cobra.Command{ lg.Fatal().Err(err).Msg("failed to load store") } + if viper.GetString("deployment") != "" { + lg. + Fatal(). + Msg("cannot use option -d,--deployment for this command") + } + + name := "" + if len(args) > 0 { + name = args[0] + } else { + name = getNewDeploymentName(ctx) + } + st := &dagger.DeploymentState{ - Name: getNewDeploymentName(ctx), + Name: name, PlanSource: getPlanSource(ctx), } @@ -65,11 +78,6 @@ var newCmd = &cobra.Command{ func getNewDeploymentName(ctx context.Context) string { lg := log.Ctx(ctx) - deploymentName := viper.GetString("name") - if deploymentName != "" { - return deploymentName - } - workDir, err := os.Getwd() if err != nil { lg. @@ -99,7 +107,6 @@ func getPlanSource(ctx context.Context) dagger.Input { } func init() { - newCmd.Flags().StringP("name", "n", "", "Specify a deployment name") newCmd.Flags().BoolP("up", "u", false, "Bring the deployment online") newCmd.Flags().String("plan-dir", "", "Load plan from a local directory")