Skip to content

Commit

Permalink
Improve the content of the default generated README.md file
Browse files Browse the repository at this point in the history
  • Loading branch information
mortent committed Sep 15, 2020
1 parent 901b5c4 commit 48ba56f
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 22 deletions.
41 changes: 30 additions & 11 deletions internal/cmdinit/cmdinit.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"io/ioutil"
"os"
"path/filepath"
"strings"
"text/template"

docs "github.com/GoogleContainerTools/kpt/internal/docs/generated/pkgdocs"
Expand Down Expand Up @@ -138,7 +139,10 @@ func (r *Runner) runE(c *cobra.Command, args []string) error {
return err
}

err = ioutil.WriteFile(filepath.Join(args[0], man.ManFilename), buff.Bytes(), 0600)
// Replace single quotes with backticks.
content := strings.ReplaceAll(buff.String(), "'", "`")

err = ioutil.WriteFile(filepath.Join(args[0], man.ManFilename), []byte(content), 0600)
if err != nil {
return err
}
Expand All @@ -147,21 +151,36 @@ func (r *Runner) runE(c *cobra.Command, args []string) error {
return nil
}

var manTemplate = `{{.Name}}
==================================================
# NAME
// manTemplate is the content for the automatically generated README.md file.
// It uses ' instead of ` since golang doesn't allow using ` in a raw string
// literal. We do a replace on the content before printing.
var manTemplate = `# {{.Name}}
{{.Name}}
## Description
{{.Description}}
# SYNOPSIS
## Usage
kubectl apply --recursive -f {{.Name}}
### Fetch the package
'kpt pkg get REPO_URI[.git]/PKG_PATH[@VERSION] {{.Name}}'
Details: https://googlecontainertools.github.io/kpt/reference/pkg/get/
# Description
### View package content
'kpt cfg tree {{.Name}}'
Details: https://googlecontainertools.github.io/kpt/reference/cfg/tree/
{{.Description}}
### List setters
'kpt cfg list-setters {{.Name}}'
Details: https://googlecontainertools.github.io/kpt/reference/cfg/list-setters/
# SEE ALSO
### Set a value
'kpt cfg set {{.Name}} NAME VALUE'
Details: https://googlecontainertools.github.io/kpt/reference/cfg/set/
### Apply the package
'''
kpt live init {{.Name}}
kpt live apply {{.Name}} --reconcile-timeout=2m --output=table
'''
Details: https://googlecontainertools.github.io/kpt/reference/live/
`
35 changes: 24 additions & 11 deletions internal/cmdinit/cmdinit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"io/ioutil"
"os"
"path/filepath"
"strings"
"testing"

"github.com/GoogleContainerTools/kpt/internal/cmdinit"
Expand Down Expand Up @@ -51,24 +52,36 @@ packageMetadata:

b, err = ioutil.ReadFile(filepath.Join(d, "my-pkg", man.ManFilename))
assert.NoError(t, err)
assert.Equal(t, `my-pkg
==================================================
assert.Equal(t, strings.ReplaceAll(`# my-pkg
# NAME
my-pkg
## Description
my description
# SYNOPSIS
## Usage
kubectl apply --recursive -f my-pkg
### Fetch the package
'kpt pkg get REPO_URI[.git]/PKG_PATH[@VERSION] my-pkg'
Details: https://googlecontainertools.github.io/kpt/reference/pkg/get/
# Description
### View package content
'kpt cfg tree my-pkg'
Details: https://googlecontainertools.github.io/kpt/reference/cfg/tree/
my description
### List setters
'kpt cfg list-setters my-pkg'
Details: https://googlecontainertools.github.io/kpt/reference/cfg/list-setters/
# SEE ALSO
### Set a value
'kpt cfg set my-pkg NAME VALUE'
Details: https://googlecontainertools.github.io/kpt/reference/cfg/set/
`, string(b))
### Apply the package
'''
kpt live init my-pkg
kpt live apply my-pkg --reconcile-timeout=2m --output=table
'''
Details: https://googlecontainertools.github.io/kpt/reference/live/
`, "'", "`"), string(b))
}

func TestCmd_currentDir(t *testing.T) {
Expand Down

0 comments on commit 48ba56f

Please sign in to comment.