MCPcopy Index your code
hub / github.com/coder/coder / templateList

Method templateList

cli/templatelist.go:13–52  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

11)
12
13func (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}

Callers 1

templatesMethod · 0.95

Calls 9

InitClientMethod · 0.95
FormatMethod · 0.95
AttachOptionsMethod · 0.95
NewOutputFormatterFunction · 0.92
TableFormatFunction · 0.92
JSONFormatFunction · 0.92
templatesToRowsFunction · 0.85
TemplatesMethod · 0.80
ContextMethod · 0.65

Tested by

no test coverage detected