cmd/new: implemented optional arg to specify name, forbid usage of -d option

Signed-off-by: Sam Alba <sam.alba@gmail.com>
This commit is contained in:
Sam Alba 2021-04-01 10:49:17 -07:00
parent 47b16a1d1b
commit b9b195b70f

View File

@ -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")