github.com/graywolf-at-work-2/terraform-vendor@v1.4.5/internal/command/arguments/view.go (about) 1 package arguments 2 3 // View represents the global command-line arguments which configure the view. 4 type View struct { 5 // NoColor is used to disable the use of terminal color codes in all 6 // output. 7 NoColor bool 8 9 // CompactWarnings is used to coalesce duplicate warnings, to reduce the 10 // level of noise when multiple instances of the same warning are raised 11 // for a configuration. 12 CompactWarnings bool 13 } 14 15 // ParseView processes CLI arguments, returning a View value and a 16 // possibly-modified slice of arguments. If any of the supported flags are 17 // found, they will be removed from the slice. 18 func ParseView(args []string) (*View, []string) { 19 common := &View{} 20 21 // Keep track of the length of the returned slice. When we find an 22 // argument we support, i will not be incremented. 23 i := 0 24 for _, v := range args { 25 switch v { 26 case "-no-color": 27 common.NoColor = true 28 case "-compact-warnings": 29 common.CompactWarnings = true 30 default: 31 // Unsupported argument: move left to the current position, and 32 // increment the index. 33 args[i] = v 34 i++ 35 } 36 } 37 38 // Reduce the slice to the number of unsupported arguments. Any remaining 39 // to the right of i have already been moved left. 40 args = args[:i] 41 42 return common, args 43 }