8000 cli/templateinit: add links to template READMEs by johnstcn · Pull Request #2576 · coder/coder · GitHub
[go: up one dir, main page]

Skip to content

cli/templateinit: add links to template READMEs #2576

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cli/cliui/cliui.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,5 @@ var Styles = struct {
Fuschia: defaultStyles.SelectedMenuItem.Copy(),
Logo: defaultStyles.Logo.SetString("Coder"),
Warn: lipgloss.NewStyle().Foreground(lipgloss.AdaptiveColor{Light: "#04B575", Dark: "#ECFD65"}),
Wrap: defaultStyles.Wrap,
Wrap: lipgloss.NewStyle().Width(80),
}
3 changes: 2 additions & 1 deletion cli/templateinit.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ func templateInit() *cobra.Command {
exampleByName := map[string]examples.Example{}
for _, example := range exampleList {
name := fmt.Sprintf(
"%s\n%s\n",
"%s\n%s\n%s\n",
cliui.Styles.Bold.Render(example.Name),
cliui.Styles.Wrap.Copy().PaddingLeft(6).Render(example.Description),
cliui.Styles.Keyword.PaddingLeft(6).Render(example.URL),
)
exampleNames = append(exampleNames, name)
exampleByName[name] = example
Expand Down
10 changes: 7 additions & 3 deletions examples/examples.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ var (
//go:embed templates
files embed.FS

examples = make([]Example, 0)
parseExamples sync.Once
archives = singleflight.Group{}
exampleBasePath = "https://github.com/coder/coder/tree/main/examples/templates/"
examples = make([]Example, 0)
parseExamples sync.Once
archives = singleflight.Group{}
)

type Example struct {
ID string `json:"id"`
URL string `json:"url"`
Name string `json:"name"`
Description string `json:"description"`
Markdown string `json:"markdown"`
Expand Down Expand Up @@ -52,6 +54,7 @@ func List() ([]Example, error) {
continue
}
exampleID := dir.Name()
exampleURL := exampleBasePath + exampleID
// Each one of these is a example!
readme, err := fs.ReadFile(files, path.Join(dir.Name(), "README.md"))
if err != nil {
Expand Down Expand Up @@ -91,6 +94,7 @@ func List() ([]Example, error) {

examples = append(examples, Example{
ID: exampleID,
URL: exampleURL,
Name: name,
Description: description,
Markdown: string(frontMatter.Content),
Expand Down
19 changes: 15 additions & 4 deletions examples/examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"io"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/coder/coder/examples"
Expand All @@ -16,10 +17,20 @@ func TestTemplate(t *testing.T) {
t.Parallel()
list, err := examples.List()
require.NoError(t, err)
require.Greater(t, len(list), 0)

_, err = examples.Archive(list[0].ID)
require.NoError(t, err)
require.NotEmpty(t, list)
for _, eg := range list {
eg := eg
t.Run(eg.ID, func(t *testing.T) {
t.Parallel()
assert.NotEmpty(t, eg.ID, "example ID should not be empty")
assert.NotEmpty(t, eg.URL, "example URL should not be empty")
assert.NotEmpty(t, eg.Name, "example name should not be empty")
assert.NotEmpty(t, eg.Description, "example description should not be empty")
assert.NotEmpty(t, eg.Markdown, "example markdown should not be empty")
_, err := examples.Archive(eg.ID)
assert.NoError(t, err, "error archiving example")
})
}
}

func TestSubdirs(t *testing.T) {
Expand Down
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
0