mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-10-05 10:11:11 +00:00
961c878e0d
Switch to using Go modules. This migrates our vendor.json to use Go 1.11's modules system, and replaces the vendor folder with the output of go mod vendor. The vendored code should remain basically the same; I believe some tree shaking of packages and support scripts/licenses/READMEs/etc. happened. This also fixes Travis and our Makefile to no longer use govendor.
51 lines
1.2 KiB
Go
51 lines
1.2 KiB
Go
package install
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
"text/template"
|
|
)
|
|
|
|
// (un)install in fish
|
|
|
|
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)
|
|
if _, err := os.Stat(completionFile); err == nil {
|
|
return fmt.Errorf("already installed at %s", completionFile)
|
|
}
|
|
|
|
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 {
|
|
return fmt.Errorf("does not installed in %s", f.configDir)
|
|
}
|
|
|
|
return os.Remove(completionFile)
|
|
}
|
|
|
|
func (f fish) cmd(cmd, bin string) string {
|
|
var buf bytes.Buffer
|
|
params := struct{ Cmd, Bin string }{cmd, bin}
|
|
template.Must(template.New("cmd").Parse(`
|
|
function __complete_{{.Cmd}}
|
|
set -lx COMP_LINE (string join ' ' (commandline -o))
|
|
test (commandline -ct) = ""
|
|
and set COMP_LINE "$COMP_LINE "
|
|
{{.Bin}}
|
|
end
|
|
complete -c {{.Cmd}} -a "(__complete_{{.Cmd}})"
|
|
`)).Execute(&buf, params)
|
|
|
|
return string(buf.Bytes())
|
|
}
|