Skip to content

Commit 9d18c53

Browse files
committed
refactor configuration of flagOptions
1 parent e0591af commit 9d18c53

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

internal/cmd/volume/backup/create/create.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ const (
3030
labelsFlag = "labels"
3131
)
3232

33+
var sourceTypeFlagOptions = []string{"volume", "snapshot"}
34+
3335
type inputModel struct {
3436
*globalflags.GlobalFlagModel
3537
SourceID string
@@ -128,7 +130,7 @@ func NewCmd(params *params.CmdParams) *cobra.Command {
128130

129131
func configureFlags(cmd *cobra.Command) {
130132
cmd.Flags().String(sourceIdFlag, "", "ID of the source from which a backup should be created")
131-
cmd.Flags().String(sourceTypeFlag, "", "Source type of the backup (volume or snapshot)")
133+
cmd.Flags().Var(flags.EnumFlag(false, "", sourceTypeFlagOptions...), sourceTypeFlag, fmt.Sprintf("Source type of the backup, one of %q", sourceTypeFlagOptions))
132134
cmd.Flags().String(nameFlag, "", "Name of the backup")
133135
cmd.Flags().StringToString(labelsFlag, nil, "Key-value string pairs as labels")
134136

@@ -148,9 +150,6 @@ func parseInput(p *print.Printer, cmd *cobra.Command) (*inputModel, error) {
148150
}
149151

150152
sourceType := flags.FlagToStringValue(p, cmd, sourceTypeFlag)
151-
if sourceType != "volume" && sourceType != "snapshot" {
152-
return nil, fmt.Errorf("source-type must be either 'volume' or 'snapshot'")
153-
}
154153

155154
name := flags.FlagToStringPointer(p, cmd, nameFlag)
156155
labels := flags.FlagToStringToStringPointer(p, cmd, labelsFlag)

0 commit comments

Comments
 (0)