Skip to content

Commit

Permalink
refactor arg validation
Browse files Browse the repository at this point in the history
Signed-off-by: Ayush Rangwala <[email protected]>
  • Loading branch information
aayushrangwala committed Dec 17, 2023
1 parent 9fba494 commit e2f6f0b
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions internal/interconnections/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,13 @@ func (c *Client) Create() *cobra.Command {
RunE: func(cmd *cobra.Command, args []string) error {
cmd.SilenceUsage = true

if projectID == "" && organizationID == "" {
return errors.New("could you provide at least either of projectID OR organizationID")
}

if vlanFabricVcCreate(vlans) || vrfsFabricVcCreate(vrfs) && svcTokenType == "" {
return errors.New("flag 'service-token-type' is required for vlan or vrfs fabric VC create")
}

var interconn *metal.Interconnection
var err error

if err := validInputArgs(projectID, organizationID, vlans, vrfs, svcTokenType); err != nil {
return err
}

createOrganizationInterconnectionRequest := metal.CreateOrganizationInterconnectionRequest{}

switch true {
Expand Down Expand Up @@ -131,3 +127,15 @@ func (c *Client) handleCreate(projectID, organizationID string,
Execute()
return interconn, err
}

func validInputArgs(projectID, organizationID string, vlans []int32, vrfs []string, svcTokenType string) error {
if projectID == "" && organizationID == "" {
return errors.New("could you provide at least either of projectID OR organizationID")
}

if vlanFabricVcCreate(vlans) || vrfsFabricVcCreate(vrfs) && svcTokenType == "" {
return errors.New("flag 'service-token-type' is required for vlan or vrfs fabric VC create")
}

return nil
}

0 comments on commit e2f6f0b

Please sign in to comment.