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

Method templatePresetsList

cli/templatepresets.go:41–140  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

39}
40
41func (r *RootCmd) templatePresetsList() *serpent.Command {
42 defaultColumns := []string{
43 "name",
44 "description",
45 "parameters",
46 "default",
47 "desired prebuild instances",
48 }
49 formatter := cliui.NewOutputFormatter(
50 cliui.TableFormat([]TemplatePresetRow{}, defaultColumns),
51 cliui.JSONFormat(),
52 )
53 orgContext := NewOrganizationContext()
54
55 var templateVersion string
56
57 cmd := &serpent.Command{
58 Use: "list <template>",
59 Middleware: serpent.Chain(
60 serpent.RequireNArgs(1),
61 ),
62 Short: "List all presets of the specified template. Defaults to the active template version.",
63 Options: serpent.OptionSet{
64 {
65 Name: "template-version",
66 Description: "Specify a template version to list presets for. Defaults to the active version.",
67 Flag: "template-version",
68 Value: serpent.StringOf(&templateVersion),
69 },
70 },
71 Handler: func(inv *serpent.Invocation) error {
72 client, err := r.InitClient(inv)
73 if err != nil {
74 return err
75 }
76 organization, err := orgContext.Selected(inv, client)
77 if err != nil {
78 return xerrors.Errorf("get current organization: %w", err)
79 }
80
81 template, err := client.TemplateByName(inv.Context(), organization.ID, inv.Args[0])
82 if err != nil {
83 return xerrors.Errorf("get template by name: %w", err)
84 }
85
86 // If a template version is specified via flag, fetch that version by name
87 var version codersdk.TemplateVersion
88 if len(templateVersion) > 0 {
89 version, err = client.TemplateVersionByName(inv.Context(), template.ID, templateVersion)
90 if err != nil {
91 return xerrors.Errorf("get template version by name: %w", err)
92 }
93 } else {
94 // Otherwise, use the template's active version
95 version, err = client.TemplateVersion(inv.Context(), template.ActiveVersionID)
96 if err != nil {
97 return xerrors.Errorf("get active template version: %w", err)
98 }

Callers 1

templatePresetsMethod · 0.95

Calls 15

InitClientMethod · 0.95
SelectedMethod · 0.95
FormatIDMethod · 0.95
FormatMethod · 0.95
AttachOptionsMethod · 0.95
AttachOptionsMethod · 0.95
NewOutputFormatterFunction · 0.92
TableFormatFunction · 0.92
JSONFormatFunction · 0.92
InfofFunction · 0.92
NewOrganizationContextFunction · 0.85
templatePresetsToRowsFunction · 0.85

Tested by

no test coverage detected