| 48 | } |
| 49 | |
| 50 | func runTemplatesList(_ *cobra.Command, _ []string) error { |
| 51 | if err := ValidateFormat(templatesFormat, []string{"table", "json", "yaml"}); err != nil { |
| 52 | return err |
| 53 | } |
| 54 | |
| 55 | projectRoot := resolveProjectRoot() |
| 56 | userHome, _ := os.UserHomeDir() |
| 57 | |
| 58 | templates := template.Discover(projectRoot, userHome) |
| 59 | |
| 60 | items := make([]templateListItem, len(templates)) |
| 61 | for i, tmpl := range templates { |
| 62 | items[i] = templateListItem{ |
| 63 | Name: tmpl.Name, |
| 64 | Description: tmpl.Description, |
| 65 | Source: tmpl.Source, |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | switch templatesFormat { |
| 70 | case "json": |
| 71 | return WriteJSON(os.Stdout, items) |
| 72 | case "yaml": |
| 73 | return WriteYAML(os.Stdout, items) |
| 74 | default: |
| 75 | return outputTemplatesTable(items) |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | func outputTemplatesTable(items []templateListItem) error { |
| 80 | if len(items) == 0 { |