Format formats the given data using the format specified by the --output flag. If the flag is not set, the default format is used.
(ctx context.Context, data any)
| 74 | // Format formats the given data using the format specified by the --output |
| 75 | // flag. If the flag is not set, the default format is used. |
| 76 | func (f *OutputFormatter) Format(ctx context.Context, data any) (string, error) { |
| 77 | for _, format := range f.formats { |
| 78 | if format.ID() == f.formatID { |
| 79 | return format.Format(ctx, data) |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | return "", xerrors.Errorf("unknown output format %q", f.formatID) |
| 84 | } |
| 85 | |
| 86 | // FormatID will return the ID of the format selected by `--output`. |
| 87 | // If no flag is present, it returns the 'default' formatter. |