SetListFormat sets opt.ListFormat for destAfter TODO: possibly refactor duplicate code from cmd/lsf, where this is mostly copied from
(ctx context.Context, cmdFlags *pflag.FlagSet)
| 305 | // SetListFormat sets opt.ListFormat for destAfter |
| 306 | // TODO: possibly refactor duplicate code from cmd/lsf, where this is mostly copied from |
| 307 | func (opt *LoggerOpt) SetListFormat(ctx context.Context, cmdFlags *pflag.FlagSet) { |
| 308 | // Work out if the separatorFlag was supplied or not |
| 309 | separatorFlag := cmdFlags.Lookup("separator") |
| 310 | separatorFlagSupplied := separatorFlag != nil && separatorFlag.Changed |
| 311 | // Default the separator to , if using CSV |
| 312 | if opt.Csv && !separatorFlagSupplied { |
| 313 | opt.Separator = "," |
| 314 | } |
| 315 | |
| 316 | var list ListFormat |
| 317 | list.SetSeparator(opt.Separator) |
| 318 | list.SetCSV(opt.Csv) |
| 319 | list.SetDirSlash(opt.DirSlash) |
| 320 | list.SetAbsolute(opt.Absolute) |
| 321 | var JSONOpt = ListJSONOpt{ |
| 322 | NoModTime: true, |
| 323 | NoMimeType: true, |
| 324 | DirsOnly: opt.DirsOnly, |
| 325 | FilesOnly: opt.FilesOnly, |
| 326 | // Recurse: opt.Recurse, |
| 327 | } |
| 328 | |
| 329 | for _, char := range opt.Format { |
| 330 | switch char { |
| 331 | case 'p': |
| 332 | list.AddPath() |
| 333 | case 't': |
| 334 | list.AddModTime(opt.TimeFormat) |
| 335 | JSONOpt.NoModTime = false |
| 336 | case 's': |
| 337 | list.AddSize() |
| 338 | case 'h': |
| 339 | list.AddHash(opt.HashType) |
| 340 | JSONOpt.ShowHash = true |
| 341 | JSONOpt.HashTypes = []string{opt.HashType.String()} |
| 342 | case 'i': |
| 343 | list.AddID() |
| 344 | case 'm': |
| 345 | list.AddMimeType() |
| 346 | JSONOpt.NoMimeType = false |
| 347 | case 'e': |
| 348 | list.AddEncrypted() |
| 349 | JSONOpt.ShowEncrypted = true |
| 350 | case 'o': |
| 351 | list.AddOrigID() |
| 352 | JSONOpt.ShowOrigIDs = true |
| 353 | case 'T': |
| 354 | list.AddTier() |
| 355 | case 'M': |
| 356 | list.AddMetadata() |
| 357 | JSONOpt.Metadata = true |
| 358 | default: |
| 359 | fs.Errorf(nil, "unknown format character %q", char) |
| 360 | } |
| 361 | } |
| 362 | opt.ListFormat = list |
| 363 | opt.JSONOpt = JSONOpt |
| 364 | } |
no test coverage detected