Skip to content

Commit

Permalink
fix: skip prompting when no-input is set
Browse files Browse the repository at this point in the history
  • Loading branch information
majori committed Jul 17, 2024
1 parent 4291d87 commit 99e778f
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions internal/cli/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ func runUpgrade(cmd *cobra.Command, opts upgradeOptions) error {
if len(varsWithoutValues) > 0 {
// If --no-input flag is set, try to use default values
if opts.NoInput {
varsWithoutDefaultValues := make([]recipe.Variable, 0, len(varsWithoutValues))
varsEvenWithoutDefaultValues := make([]recipe.Variable, 0, len(varsWithoutValues))
for _, v := range varsWithoutValues {
if v.Default != "" {
defaultValue, err := v.ParseDefaultValue()
Expand All @@ -240,29 +240,30 @@ func runUpgrade(cmd *cobra.Command, opts upgradeOptions) error {
}
values[v.Name] = defaultValue
} else {
varsWithoutDefaultValues = append(varsWithoutDefaultValues, v)
varsEvenWithoutDefaultValues = append(varsEvenWithoutDefaultValues, v)
}
}

// If there are still variables without values, return error
if len(varsWithoutDefaultValues) > 0 {
return recipeutil.NewNoInputError(varsWithoutDefaultValues)
if len(varsEvenWithoutDefaultValues) > 0 {
return recipeutil.NewNoInputError(varsEvenWithoutDefaultValues)
}
}

cmd.Println()
promptedValues, err := survey.PromptUserForValues(
cmd.InOrStdin(),
cmd.OutOrStdout(),
varsWithoutValues,
values,
)
} else {
cmd.Println()
promptedValues, err := survey.PromptUserForValues(
cmd.InOrStdin(),
cmd.OutOrStdout(),
varsWithoutValues,
values,
)

if err != nil {
return fmt.Errorf("error when prompting for values: %w", err)
}
if err != nil {
return fmt.Errorf("error when prompting for values: %w", err)
}

values = recipeutil.MergeValues(values, promptedValues)
values = recipeutil.MergeValues(values, promptedValues)
}
}

newSauce, err := re.Execute(engine.New(), values, oldSauce.ID)
Expand Down

0 comments on commit 99e778f

Please sign in to comment.