mirror of
https://github.com/edgelesssys/constellation.git
synced 2025-05-16 13:12:21 -04:00
monorepo
Co-authored-by: Malte Poll <mp@edgeless.systems> Co-authored-by: katexochen <katexochen@users.noreply.github.com> Co-authored-by: Daniel Weiße <dw@edgeless.systems> Co-authored-by: Thomas Tendyck <tt@edgeless.systems> Co-authored-by: Benedict Schlueter <bs@edgeless.systems> Co-authored-by: leongross <leon.gross@rub.de> Co-authored-by: Moritz Eckert <m1gh7ym0@gmail.com>
This commit is contained in:
commit
2d8fcd9bf4
362 changed files with 50980 additions and 0 deletions
70
cli/cmd/validargs.go
Normal file
70
cli/cmd/validargs.go
Normal file
|
@ -0,0 +1,70 @@
|
|||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/edgelesssys/constellation/cli/azure"
|
||||
"github.com/edgelesssys/constellation/cli/ec2"
|
||||
"github.com/edgelesssys/constellation/cli/gcp"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
// isIntArg checks if argument at position arg is an integer.
|
||||
func isIntArg(arg int) cobra.PositionalArgs {
|
||||
return func(cmd *cobra.Command, args []string) error {
|
||||
if _, err := strconv.Atoi(args[arg]); err != nil {
|
||||
return fmt.Errorf("argument %d must be an integer", arg)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// isIntGreaterArg checks if argument at position arg is and integer and greater i.
|
||||
func isIntGreaterArg(arg int, i int) cobra.PositionalArgs {
|
||||
return cobra.MatchAll(isIntArg(arg), func(cmd *cobra.Command, args []string) error {
|
||||
if v, _ := strconv.Atoi(args[arg]); v <= i {
|
||||
return fmt.Errorf("argument %d must be greater %d, but it's %d", arg, i, v)
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
// isIntGreaterZeroArg checks if argument at position arg is a positive non zero integer.
|
||||
func isIntGreaterZeroArg(arg int) cobra.PositionalArgs {
|
||||
return cobra.MatchAll(isIntGreaterArg(arg, 0))
|
||||
}
|
||||
|
||||
// isEC2InstanceType checks if argument at position arg is a key in m.
|
||||
// The argument will always be converted to lower case letters.
|
||||
func isEC2InstanceType(arg int) cobra.PositionalArgs {
|
||||
return func(cmd *cobra.Command, args []string) error {
|
||||
if _, ok := ec2.InstanceTypes[strings.ToLower(args[arg])]; !ok {
|
||||
return fmt.Errorf("'%s' isn't an AWS EC2 instance type", args[arg])
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func isGCPInstanceType(arg int) cobra.PositionalArgs {
|
||||
return func(cmd *cobra.Command, args []string) error {
|
||||
for _, instanceType := range gcp.InstanceTypes {
|
||||
if args[arg] == instanceType {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return fmt.Errorf("argument %s isn't a valid GCP instance type", args[arg])
|
||||
}
|
||||
}
|
||||
|
||||
func isAzureInstanceType(arg int) cobra.PositionalArgs {
|
||||
return func(cmd *cobra.Command, args []string) error {
|
||||
for _, instanceType := range azure.InstanceTypes {
|
||||
if args[arg] == instanceType {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return fmt.Errorf("argument %s isn't a valid Azure instance type", args[arg])
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue