AttachOptions attaches the --output flag to the given command, and any additional flags required by the output formatters.
(opts *serpent.OptionSet)
| 51 | // AttachOptions attaches the --output flag to the given command, and any |
| 52 | // additional flags required by the output formatters. |
| 53 | func (f *OutputFormatter) AttachOptions(opts *serpent.OptionSet) { |
| 54 | for _, format := range f.formats { |
| 55 | format.AttachOptions(opts) |
| 56 | } |
| 57 | |
| 58 | formatNames := make([]string, 0, len(f.formats)) |
| 59 | for _, format := range f.formats { |
| 60 | formatNames = append(formatNames, format.ID()) |
| 61 | } |
| 62 | |
| 63 | *opts = append(*opts, |
| 64 | serpent.Option{ |
| 65 | Flag: "output", |
| 66 | FlagShorthand: "o", |
| 67 | Default: f.formats[0].ID(), |
| 68 | Value: serpent.EnumOf(&f.formatID, formatNames...), |
| 69 | Description: "Output format.", |
| 70 | }, |
| 71 | ) |
| 72 | } |
| 73 | |
| 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. |