github.com/azunymous/cdx@v0.0.0-20201122180449-fbb46cc4d252/commands/options/increment.go (about) 1 package options 2 3 import ( 4 "github.com/azunymous/cdx/versioned" 5 "github.com/sirupsen/logrus" 6 "github.com/spf13/cobra" 7 "strings" 8 ) 9 10 // App struct contains options regarding the application 11 type Increment struct { 12 Field string 13 } 14 15 func AddIncrementArg(cmd *cobra.Command, r *Increment) { 16 cmd.Flags().StringVarP(&r.Field, "increment", "i", "minor", "Semantic version field to increment") 17 } 18 19 func (i *Increment) GetField() versioned.Field { 20 i.Field = strings.ToLower(i.Field) 21 switch i.Field { 22 case "patch": 23 return versioned.Patch 24 case "minor": 25 return versioned.Minor 26 case "major": 27 return versioned.Major 28 } 29 logrus.Fatalln("Increment field was not one of [major, minor, patch]") 30 return -1 31 }