Skip to content

Commit

Permalink
add validation for volname
Browse files Browse the repository at this point in the history
  • Loading branch information
kmova committed Oct 31, 2017
1 parent 1c46198 commit cd2ba3f
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions cmd/mayactl/app/command/volume_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ func NewCmdVolumeCreate() *cobra.Command {
Short: "Creates a new Volume",
Long: volumeCreateCommandHelpText,
Run: func(cmd *cobra.Command, args []string) {
util.CheckErr(RunVolumeCreate(cmd, &options), util.Fatal)
util.CheckErr(options.Validate(cmd), util.Fatal)
util.CheckErr(options.RunVolumeCreate(cmd), util.Fatal)
},
}

Expand All @@ -67,7 +68,15 @@ func NewCmdVolumeCreate() *cobra.Command {
}

// Run does tasks related to mayaserver.
func RunVolumeCreate(cmd *cobra.Command, c *CmdVolumeCreateOptions) error {
func (c *CmdVolumeCreateOptions) Validate(cmd *cobra.Command) error {
if c.volName == "" {
return errors.New("--volname is missing. Please specify an unique name")
}
return nil
}

// Run does tasks related to mayaserver.
func (c *CmdVolumeCreateOptions) RunVolumeCreate(cmd *cobra.Command) error {
fmt.Println("Executing volume create...")

resp := mapiserver.CreateVolume(c.volName, c.size)
Expand Down

0 comments on commit cd2ba3f

Please sign in to comment.