GetField returns fields from package
(name string)
| 249 | |
| 250 | // GetField returns fields from package |
| 251 | func (p *Package) GetField(name string) string { |
| 252 | switch name { |
| 253 | // $Version is handled in FieldQuery |
| 254 | case "$Source": |
| 255 | if p.IsSource { |
| 256 | return "" |
| 257 | } |
| 258 | source := p.Source |
| 259 | if source == "" { |
| 260 | return p.Name |
| 261 | } else if pos := strings.Index(source, "("); pos != -1 { |
| 262 | return strings.TrimSpace(source[:pos]) |
| 263 | } |
| 264 | return source |
| 265 | case "$SourceVersion": |
| 266 | if p.IsSource { |
| 267 | return "" |
| 268 | } |
| 269 | source := p.Source |
| 270 | if pos := strings.Index(source, "("); pos != -1 { |
| 271 | if pos2 := strings.LastIndex(source, ")"); pos2 != -1 && pos2 > pos { |
| 272 | return strings.TrimSpace(source[pos+1 : pos2]) |
| 273 | } |
| 274 | } |
| 275 | return p.Version |
| 276 | case "$Architecture": |
| 277 | return p.Architecture |
| 278 | case "$PackageType": |
| 279 | if p.IsSource { |
| 280 | return PackageTypeSource |
| 281 | } |
| 282 | if p.IsUdeb { |
| 283 | return PackageTypeUdeb |
| 284 | } |
| 285 | return PackageTypeBinary |
| 286 | case "Name": |
| 287 | return p.Name |
| 288 | case "Version": |
| 289 | return p.Version |
| 290 | case "Architecture": |
| 291 | if p.IsSource { |
| 292 | return p.SourceArchitecture |
| 293 | } |
| 294 | return p.Architecture |
| 295 | case "Source": |
| 296 | return p.Source |
| 297 | case "Depends": |
| 298 | return strings.Join(p.Deps().Depends, ", ") |
| 299 | case "Pre-Depends": |
| 300 | return strings.Join(p.Deps().PreDepends, ", ") |
| 301 | case "Suggests": |
| 302 | return strings.Join(p.Deps().Suggests, ", ") |
| 303 | case "Recommends": |
| 304 | return strings.Join(p.Deps().Recommends, ", ") |
| 305 | case "Provides": |
| 306 | return strings.Join(p.Provides, ", ") |
| 307 | case "Build-Depends": |
| 308 | return strings.Join(p.Deps().BuildDepends, ", ") |