CopyToGoFlagSet will add all current flags to the given Go flag set. Deprecation remarks get copied into the usage description. Whenever possible, a flag gets added for which Go flags shows a proper type in the help message.
(newSet *goflag.FlagSet)
| 119 | // Whenever possible, a flag gets added for which Go flags shows |
| 120 | // a proper type in the help message. |
| 121 | func (f *FlagSet) CopyToGoFlagSet(newSet *goflag.FlagSet) { |
| 122 | f.VisitAll(func(flag *Flag) { |
| 123 | usage := flag.Usage |
| 124 | if flag.Deprecated != "" { |
| 125 | usage += " (DEPRECATED: " + flag.Deprecated + ")" |
| 126 | } |
| 127 | |
| 128 | switch value := flag.Value.(type) { |
| 129 | case *stringValue: |
| 130 | newSet.StringVar((*string)(value), flag.Name, flag.DefValue, usage) |
| 131 | case *intValue: |
| 132 | newSet.IntVar((*int)(value), flag.Name, *(*int)(value), usage) |
| 133 | case *int64Value: |
| 134 | newSet.Int64Var((*int64)(value), flag.Name, *(*int64)(value), usage) |
| 135 | case *uintValue: |
| 136 | newSet.UintVar((*uint)(value), flag.Name, *(*uint)(value), usage) |
| 137 | case *uint64Value: |
| 138 | newSet.Uint64Var((*uint64)(value), flag.Name, *(*uint64)(value), usage) |
| 139 | case *durationValue: |
| 140 | newSet.DurationVar((*time.Duration)(value), flag.Name, *(*time.Duration)(value), usage) |
| 141 | case *float64Value: |
| 142 | newSet.Float64Var((*float64)(value), flag.Name, *(*float64)(value), usage) |
| 143 | default: |
| 144 | newSet.Var(flag.Value, flag.Name, usage) |
| 145 | } |
| 146 | }) |
| 147 | } |
| 148 | |
| 149 | // ParseSkippedFlags explicitly Parses go test flags (i.e. the one starting with '-test.') with goflag.Parse(), |
| 150 | // since by default those are skipped by pflag.Parse(). |