()
| 40 | } |
| 41 | |
| 42 | func (r *RootCmd) templateVersionsList() *serpent.Command { |
| 43 | defaultColumns := []string{ |
| 44 | "name", |
| 45 | "created at", |
| 46 | "created by", |
| 47 | "status", |
| 48 | "active", |
| 49 | } |
| 50 | formatter := cliui.NewOutputFormatter( |
| 51 | cliui.TableFormat([]templateVersionRow{}, defaultColumns), |
| 52 | cliui.JSONFormat(), |
| 53 | ) |
| 54 | orgContext := NewOrganizationContext() |
| 55 | |
| 56 | var includeArchived serpent.Bool |
| 57 | |
| 58 | cmd := &serpent.Command{ |
| 59 | Use: "list <template>", |
| 60 | Middleware: serpent.Chain( |
| 61 | serpent.RequireNArgs(1), |
| 62 | func(next serpent.HandlerFunc) serpent.HandlerFunc { |
| 63 | return func(i *serpent.Invocation) error { |
| 64 | // This is the only way to dynamically add the "archived" |
| 65 | // column if '--include-archived' is true. |
| 66 | // It does not make sense to show this column if the |
| 67 | // flag is false. |
| 68 | if includeArchived { |
| 69 | for _, opt := range i.Command.Options { |
| 70 | if opt.Flag == "column" { |
| 71 | if opt.ValueSource == serpent.ValueSourceDefault { |
| 72 | v, ok := opt.Value.(*serpent.EnumArray) |
| 73 | if ok { |
| 74 | // Add the extra new default column. |
| 75 | _ = v.Append("Archived") |
| 76 | } |
| 77 | } |
| 78 | break |
| 79 | } |
| 80 | } |
| 81 | } |
| 82 | return next(i) |
| 83 | } |
| 84 | }, |
| 85 | ), |
| 86 | Short: "List all the versions of the specified template", |
| 87 | Options: serpent.OptionSet{ |
| 88 | { |
| 89 | Name: "include-archived", |
| 90 | Description: "Include archived versions in the result list.", |
| 91 | Flag: "include-archived", |
| 92 | Value: &includeArchived, |
| 93 | }, |
| 94 | }, |
| 95 | Handler: func(inv *serpent.Invocation) error { |
| 96 | client, err := r.InitClient(inv) |
| 97 | if err != nil { |
| 98 | return err |
| 99 | } |
no test coverage detected