github.com/taubyte/tau-cli@v0.1.13-0.20240326000942-487f0d57edfc/cli/args/flags.go (about) 1 package args 2 3 import ( 4 "github.com/taubyte/tau-cli/flags" 5 "github.com/urfave/cli/v2" 6 ) 7 8 /* 9 Gets a string slice from cli.flags so that they can be moved to their required 10 position from anywhere. 11 This way `tau new --e` and `tau --e new` are both valid commands. 12 */ 13 func ParseFlags(flags []cli.Flag) []ParsedFlag { 14 valid := make([]ParsedFlag, len(flags)) 15 for idx, flag := range flags { 16 valid[idx] = ParseFlag(flag) 17 } 18 19 return valid 20 } 21 22 func ParseFlag(flag cli.Flag) ParsedFlag { 23 names := make([]string, 0) 24 for _, name := range flag.Names() { 25 names = append(names, 26 "-"+name, 27 "--"+name, 28 ) 29 } 30 31 _, isBoolFlag := flag.(*cli.BoolFlag) 32 33 if !isBoolFlag { 34 _, isBoolFlag = flag.(*flags.BoolWithInverseFlag) 35 } 36 37 return ParsedFlag{names, isBoolFlag} 38 }