Bump github.com/hashicorp/terraform-plugin-docs from 0.7.0 to 0.13.0

Bumps [github.com/hashicorp/terraform-plugin-docs](https://github.com/hashicorp/terraform-plugin-docs) from 0.7.0 to 0.13.0.
- [Release notes](https://github.com/hashicorp/terraform-plugin-docs/releases)
- [Changelog](https://github.com/hashicorp/terraform-plugin-docs/blob/main/CHANGELOG.md)
- [Commits](https://github.com/hashicorp/terraform-plugin-docs/compare/v0.7.0...v0.13.0)

---
updated-dependencies:
- dependency-name: github.com/hashicorp/terraform-plugin-docs
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
This commit is contained in:
dependabot[bot]
2022-12-18 17:14:23 +00:00
committed by GitHub
parent ad07770b6b
commit b4859cda6b
210 changed files with 32649 additions and 2138 deletions

View File

@ -10,20 +10,25 @@ type bash struct {
rc string
}
func (b bash) Install(cmd, bin string) error {
func (b bash) IsInstalled(cmd, bin string) bool {
completeCmd := b.cmd(cmd, bin)
if lineInFile(b.rc, completeCmd) {
return lineInFile(b.rc, completeCmd)
}
func (b bash) Install(cmd, bin string) error {
if b.IsInstalled(cmd, bin) {
return fmt.Errorf("already installed in %s", b.rc)
}
completeCmd := b.cmd(cmd, bin)
return appendToFile(b.rc, completeCmd)
}
func (b bash) Uninstall(cmd, bin string) error {
completeCmd := b.cmd(cmd, bin)
if !lineInFile(b.rc, completeCmd) {
if !b.IsInstalled(cmd, bin) {
return fmt.Errorf("does not installed in %s", b.rc)
}
completeCmd := b.cmd(cmd, bin)
return removeFromFile(b.rc, completeCmd)
}

View File

@ -14,37 +14,56 @@ type fish struct {
configDir string
}
func (f fish) Install(cmd, bin string) error {
completionFile := filepath.Join(f.configDir, "completions", fmt.Sprintf("%s.fish", cmd))
completeCmd := f.cmd(cmd, bin)
func (f fish) IsInstalled(cmd, bin string) bool {
completionFile := f.getCompletionFilePath(cmd)
if _, err := os.Stat(completionFile); err == nil {
return fmt.Errorf("already installed at %s", completionFile)
return true
}
return false
}
func (f fish) Install(cmd, bin string) error {
if f.IsInstalled(cmd, bin) {
return fmt.Errorf("already installed at %s", f.getCompletionFilePath(cmd))
}
completionFile := f.getCompletionFilePath(cmd)
completeCmd, err := f.cmd(cmd, bin)
if err != nil {
return err
}
return createFile(completionFile, completeCmd)
}
func (f fish) Uninstall(cmd, bin string) error {
completionFile := filepath.Join(f.configDir, "completions", fmt.Sprintf("%s.fish", cmd))
if _, err := os.Stat(completionFile); err != nil {
if !f.IsInstalled(cmd, bin) {
return fmt.Errorf("does not installed in %s", f.configDir)
}
completionFile := f.getCompletionFilePath(cmd)
return os.Remove(completionFile)
}
func (f fish) cmd(cmd, bin string) string {
func (f fish) getCompletionFilePath(cmd string) string {
return filepath.Join(f.configDir, "completions", fmt.Sprintf("%s.fish", cmd))
}
func (f fish) cmd(cmd, bin string) (string, error) {
var buf bytes.Buffer
params := struct{ Cmd, Bin string }{cmd, bin}
template.Must(template.New("cmd").Parse(`
tmpl := template.Must(template.New("cmd").Parse(`
function __complete_{{.Cmd}}
set -lx COMP_LINE (string join ' ' (commandline -o))
test (commandline -ct) = ""
set -lx COMP_LINE (commandline -cp)
test -z (commandline -ct)
and set COMP_LINE "$COMP_LINE "
{{.Bin}}
end
complete -c {{.Cmd}} -a "(__complete_{{.Cmd}})"
`)).Execute(&buf, params)
return string(buf.Bytes())
complete -f -c {{.Cmd}} -a "(__complete_{{.Cmd}})"
`))
err := tmpl.Execute(&buf, params)
if err != nil {
return "", err
}
return buf.String(), nil
}

View File

@ -5,11 +5,13 @@ import (
"os"
"os/user"
"path/filepath"
"runtime"
"github.com/hashicorp/go-multierror"
)
type installer interface {
IsInstalled(cmd, bin string) bool
Install(cmd, bin string) error
Uninstall(cmd, bin string) error
}
@ -36,6 +38,24 @@ func Install(cmd string) error {
return err
}
// IsInstalled returns true if the completion
// for the given cmd is installed.
func IsInstalled(cmd string) bool {
bin, err := getBinaryPath()
if err != nil {
return false
}
for _, i := range installers() {
installed := i.IsInstalled(cmd, bin)
if installed {
return true
}
}
return false
}
// Uninstall complete command given:
// cmd: is the command name
func Uninstall(cmd string) error {
@ -51,7 +71,7 @@ func Uninstall(cmd string) error {
for _, i := range is {
errI := i.Uninstall(cmd, bin)
if errI != nil {
multierror.Append(err, errI)
err = multierror.Append(err, errI)
}
}
@ -59,7 +79,16 @@ func Uninstall(cmd string) error {
}
func installers() (i []installer) {
for _, rc := range [...]string{".bashrc", ".bash_profile", ".bash_login", ".profile"} {
// The list of bash config files candidates where it is
// possible to install the completion command.
var bashConfFiles []string
switch runtime.GOOS {
case "darwin":
bashConfFiles = []string{".bash_profile"}
default:
bashConfFiles = []string{".bashrc", ".bash_profile", ".bash_login", ".profile"}
}
for _, rc := range bashConfFiles {
if f := rcFile(rc); f != "" {
i = append(i, bash{f})
break

View File

@ -115,7 +115,10 @@ func removeContentToTempFile(name, content string) (string, error) {
if str == content {
continue
}
wf.WriteString(str + "\n")
_, err = wf.WriteString(str + "\n")
if err != nil {
return "", err
}
prefix = prefix[:0]
}
return wf.Name(), nil

View File

@ -11,12 +11,17 @@ type zsh struct {
rc string
}
func (z zsh) Install(cmd, bin string) error {
func (z zsh) IsInstalled(cmd, bin string) bool {
completeCmd := z.cmd(cmd, bin)
if lineInFile(z.rc, completeCmd) {
return lineInFile(z.rc, completeCmd)
}
func (z zsh) Install(cmd, bin string) error {
if z.IsInstalled(cmd, bin) {
return fmt.Errorf("already installed in %s", z.rc)
}
completeCmd := z.cmd(cmd, bin)
bashCompInit := "autoload -U +X bashcompinit && bashcompinit"
if !lineInFile(z.rc, bashCompInit) {
completeCmd = bashCompInit + "\n" + completeCmd
@ -26,11 +31,11 @@ func (z zsh) Install(cmd, bin string) error {
}
func (z zsh) Uninstall(cmd, bin string) error {
completeCmd := z.cmd(cmd, bin)
if !lineInFile(z.rc, completeCmd) {
if !z.IsInstalled(cmd, bin) {
return fmt.Errorf("does not installed in %s", z.rc)
}
completeCmd := z.cmd(cmd, bin)
return removeFromFile(z.rc, completeCmd)
}