From 467feac06837b75e7e0faa1be766d1bdb6b36a31 Mon Sep 17 00:00:00 2001 From: umarcor Date: Fri, 7 Jun 2019 19:56:26 +0200 Subject: [PATCH] remove unused 'isEmpty', 'executeTemplate', 'writeStringToFile', 'update' and 'checkLackFiles' --- cobra/cmd/golden_test.go | 17 -------------- cobra/cmd/helpers.go | 48 ---------------------------------------- 2 files changed, 65 deletions(-) diff --git a/cobra/cmd/golden_test.go b/cobra/cmd/golden_test.go index 9010caa1..c2422f6d 100644 --- a/cobra/cmd/golden_test.go +++ b/cobra/cmd/golden_test.go @@ -3,14 +3,11 @@ package cmd import ( "bytes" "errors" - "flag" "fmt" "io/ioutil" "os/exec" ) -var update = flag.Bool("update", false, "update .golden files") - func init() { // Mute commands. addCmd.SetOutput(new(bytes.Buffer)) @@ -57,20 +54,6 @@ func compareFiles(pathA, pathB string) error { return nil } -// checkLackFiles checks if all elements of expected are in got. -func checkLackFiles(expected, got []string) error { - lacks := make([]string, 0, len(expected)) - for _, ev := range expected { - if !stringInStringSlice(ev, got) { - lacks = append(lacks, ev) - } - } - if len(lacks) > 0 { - return fmt.Errorf("Lack %v file(s): %v", len(lacks), lacks) - } - return nil -} - // stringInStringSlice checks if s is an element of slice. func stringInStringSlice(s string, slice []string) bool { for _, v := range slice { diff --git a/cobra/cmd/helpers.go b/cobra/cmd/helpers.go index d363d8c4..057d20db 100644 --- a/cobra/cmd/helpers.go +++ b/cobra/cmd/helpers.go @@ -14,14 +14,12 @@ package cmd import ( - "bytes" "fmt" "io" "os" "os/exec" "path/filepath" "strings" - "text/template" ) var srcPaths []string @@ -66,37 +64,6 @@ func er(msg interface{}) { } } -// isEmpty checks if a given path is empty. -// Hidden files in path are ignored. -func isEmpty(path string) bool { - fi, err := os.Stat(path) - if err != nil { - er(err) - } - - if !fi.IsDir() { - return fi.Size() == 0 - } - - f, err := os.Open(path) - if err != nil { - er(err) - } - defer f.Close() - - names, err := f.Readdirnames(-1) - if err != nil && err != io.EOF { - er(err) - } - - for _, name := range names { - if len(name) > 0 && name[0] != '.' { - return false - } - } - return true -} - // exists checks if a file or directory exists. func exists(path string) bool { if path == "" { @@ -112,21 +79,6 @@ func exists(path string) bool { return false } -func executeTemplate(tmplStr string, data interface{}) (string, error) { - tmpl, err := template.New("").Funcs(template.FuncMap{"comment": commentifyString}).Parse(tmplStr) - if err != nil { - return "", err - } - - buf := new(bytes.Buffer) - err = tmpl.Execute(buf, data) - return buf.String(), err -} - -func writeStringToFile(path string, s string) error { - return writeToFile(path, strings.NewReader(s)) -} - // writeToFile writes r to file with path only // if file/directory on given path doesn't exist. func writeToFile(path string, r io.Reader) error {