Skip to content

Commit 92bcace

Browse files
authored
cli/templateinit: add links to template READMEs (#2576)
- template init: add links to template docs - examples: add URL field to examples, ensure that example fields are always non-empty - cliui: bump wrap width to 80 from 58
1 parent 34222b2 commit 92bcace

File tree

4 files changed

+25
-9
lines changed

4 files changed

+25
-9
lines changed

cli/cliui/cliui.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,5 @@ var Styles = struct {
5252
Fuschia: defaultStyles.SelectedMenuItem.Copy(),
5353
Logo: defaultStyles.Logo.SetString("Coder"),
5454
Warn: lipgloss.NewStyle().Foreground(lipgloss.AdaptiveColor{Light: "#04B575", Dark: "#ECFD65"}),
55-
Wrap: defaultStyles.Wrap,
55+
Wrap: lipgloss.NewStyle().Width(80),
5656
}

cli/templateinit.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@ func templateInit() *cobra.Command {
2525
exampleByName := map[string]examples.Example{}
2626
for _, example := range exampleList {
2727
name := fmt.Sprintf(
28-
"%s\n%s\n",
28+
"%s\n%s\n%s\n",
2929
cliui.Styles.Bold.Render(example.Name),
3030
cliui.Styles.Wrap.Copy().PaddingLeft(6).Render(example.Description),
31+
cliui.Styles.Keyword.PaddingLeft(6).Render(example.URL),
3132
)
3233
exampleNames = append(exampleNames, name)
3334
exampleByName[name] = example

examples/examples.go

+7-3
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@ var (
1818
//go:embed templates
1919
files embed.FS
2020

21-
examples = make([]Example, 0)
22-
parseExamples sync.Once
23-
archives = singleflight.Group{}
21+
exampleBasePath = "https://github.com/coder/coder/tree/main/examples/templates/"
22+
examples = make([]Example, 0)
23+
parseExamples sync.Once
24+
archives = singleflight.Group{}
2425
)
2526

2627
type Example struct {
2728
ID string `json:"id"`
29+
URL string `json:"url"`
2830
Name string `json:"name"`
2931
Description string `json:"description"`
3032
Markdown string `json:"markdown"`
@@ -52,6 +54,7 @@ func List() ([]Example, error) {
5254
continue
5355
}
5456
exampleID := dir.Name()
57+
exampleURL := exampleBasePath + exampleID
5558
// Each one of these is a example!
5659
readme, err := fs.ReadFile(files, path.Join(dir.Name(), "README.md"))
5760
if err != nil {
@@ -91,6 +94,7 @@ func List() ([]Example, error) {
9194

9295
examples = append(examples, Example{
9396
ID: exampleID,
97+
URL: exampleURL,
9498
Name: name,
9599
Description: description,
96100
Markdown: string(frontMatter.Content),

examples/examples_test.go

+15-4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"io"
88
"testing"
99

10+
"github.com/stretchr/testify/assert"
1011
"github.com/stretchr/testify/require"
1112

1213
"github.com/coder/coder/examples"
@@ -16,10 +17,20 @@ func TestTemplate(t *testing.T) {
1617
t.Parallel()
1718
list, err := examples.List()
1819
require.NoError(t, err)
19-
require.Greater(t, len(list), 0)
20-
21-
_, err = examples.Archive(list[0].ID)
22-
require.NoError(t, err)
20+
require.NotEmpty(t, list)
21+
for _, eg := range list {
22+
eg := eg
23+
t.Run(eg.ID, func(t *testing.T) {
24+
t.Parallel()
25+
assert.NotEmpty(t, eg.ID, "example ID should not be empty")
26+
assert.NotEmpty(t, eg.URL, "example URL should not be empty")
27+
assert.NotEmpty(t, eg.Name, "example name should not be empty")
28+
assert.NotEmpty(t, eg.Description, "example description should not be empty")
29+
assert.NotEmpty(t, eg.Markdown, "example markdown should not be empty")
30+
_, err := examples.Archive(eg.ID)
31+
assert.NoError(t, err, "error archiving example")
32+
})
33+
}
2334
}
2435

2536
func TestSubdirs(t *testing.T) {

0 commit comments

Comments
 (0)