(f reflect.StructField)
| 144 | } |
| 145 | |
| 146 | func newHelpConfigKeyFromField(f reflect.StructField) (helpConfigKey, error) { |
| 147 | h := helpConfigKey{ |
| 148 | name: f.Name, |
| 149 | desc: f.Tag.Get("help"), |
| 150 | def: f.Tag.Get("default"), |
| 151 | required: f.Tag.Get("required") == "true", |
| 152 | } |
| 153 | switch f.Type.Kind() { |
| 154 | case reflect.Int: |
| 155 | h.typ = "int" |
| 156 | case reflect.String: |
| 157 | h.typ = "string" |
| 158 | h.def = `"` + h.def + `"` |
| 159 | case reflect.Slice: |
| 160 | switch f.Type.Elem().Kind() { |
| 161 | case reflect.String: |
| 162 | h.typ = "array of strings" |
| 163 | if h.def == "" { |
| 164 | h.def = "[]" |
| 165 | } |
| 166 | case reflect.Int: |
| 167 | h.typ = "array of ints" |
| 168 | default: |
| 169 | return h, fmt.Errorf("config key %q: unsupported type array of %s", f.Name, f.Type.Elem()) |
| 170 | } |
| 171 | case reflect.Int64: |
| 172 | if f.Type.Name() == "Duration" { |
| 173 | h.typ = "duration" |
| 174 | } else { |
| 175 | h.typ = "int" |
| 176 | } |
| 177 | case reflect.Bool: |
| 178 | h.typ = "bool" |
| 179 | case reflect.Map: |
| 180 | switch f.Type.Key().Kind() { |
| 181 | case reflect.String: |
| 182 | switch f.Type.Elem().Kind() { |
| 183 | case reflect.String: |
| 184 | h.typ = "map of strings to strings" |
| 185 | case reflect.Int: |
| 186 | h.typ = "map of strings to ints" |
| 187 | default: |
| 188 | return h, fmt.Errorf("config key %q: unsupported type table of %s", f.Name, f.Type.Elem()) |
| 189 | } |
| 190 | default: |
| 191 | return h, fmt.Errorf("config key %q: unsupported map with key type %s", f.Name, f.Type.Key()) |
| 192 | } |
| 193 | default: |
| 194 | // Handle other accepted types here |
| 195 | switch f.Type.Name() { |
| 196 | case "SizeBytes": |
| 197 | h.typ = "bytes as int or string with SI or IEC unit" |
| 198 | default: |
| 199 | return h, fmt.Errorf("config key %q: unsupported type %s", f.Name, f.Type) |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | return h, nil |
no test coverage detected