()
| 11 | ) |
| 12 | |
| 13 | func (r *RootCmd) templateList() *serpent.Command { |
| 14 | formatter := cliui.NewOutputFormatter( |
| 15 | cliui.TableFormat([]templateTableRow{}, []string{"name", "organization name", "last updated", "used by"}), |
| 16 | cliui.JSONFormat(), |
| 17 | ) |
| 18 | |
| 19 | cmd := &serpent.Command{ |
| 20 | Use: "list", |
| 21 | Short: "List all the templates available for the organization", |
| 22 | Aliases: []string{"ls"}, |
| 23 | Handler: func(inv *serpent.Invocation) error { |
| 24 | client, err := r.InitClient(inv) |
| 25 | if err != nil { |
| 26 | return err |
| 27 | } |
| 28 | templates, err := client.Templates(inv.Context(), codersdk.TemplateFilter{}) |
| 29 | if err != nil { |
| 30 | return err |
| 31 | } |
| 32 | |
| 33 | rows := templatesToRows(templates...) |
| 34 | out, err := formatter.Format(inv.Context(), rows) |
| 35 | if err != nil { |
| 36 | return err |
| 37 | } |
| 38 | |
| 39 | if out == "" { |
| 40 | _, _ = fmt.Fprintf(inv.Stderr, "%s No templates found! Create one:\n\n", Caret) |
| 41 | _, _ = fmt.Fprintln(inv.Stderr, color.HiMagentaString(" $ coder templates push <directory>\n")) |
| 42 | return nil |
| 43 | } |
| 44 | |
| 45 | _, err = fmt.Fprintln(inv.Stdout, out) |
| 46 | return err |
| 47 | }, |
| 48 | } |
| 49 | |
| 50 | formatter.AttachOptions(&cmd.Options) |
| 51 | return cmd |
| 52 | } |
no test coverage detected