diff --git a/pkg/cmd/download.go b/pkg/cmd/download.go index 5650aebc9b44cb66cadd0c5ce96f471ba39840d4..224facc4ce1cb99441525b5e8867617fcace73d0 100644 --- a/pkg/cmd/download.go +++ b/pkg/cmd/download.go @@ -1,19 +1,12 @@ package cmd import ( - "archive/zip" "fmt" - "io" - "io/ioutil" - "net/http" "os" - "path/filepath" - "strings" cli "github.com/spf13/cobra" "github.com/tmrts/boilr/pkg/boilr" - "github.com/tmrts/boilr/pkg/cmd/util" "github.com/tmrts/boilr/pkg/host" "github.com/tmrts/boilr/pkg/util/exit" "github.com/tmrts/boilr/pkg/util/git" @@ -22,78 +15,6 @@ import ( "github.com/tmrts/boilr/pkg/util/validate" ) -func downloadZip(URL, targetDir string) error { - f, err := ioutil.TempFile("", "boilr-download") - if err != nil { - return err - } - defer f.Close() - defer os.RemoveAll(f.Name()) - - resp, err := http.Get(URL) - if err != nil { - return err - } - defer resp.Body.Close() - - if _, err := io.Copy(f, resp.Body); err != nil { - return err - } - - if err := f.Close(); err != nil { - return err - } - - r, err := zip.OpenReader(f.Name()) - if err != nil { - return err - } - defer r.Close() - - extractFile := func(f *zip.File, dest string) error { - rc, err := f.Open() - if err != nil { - return err - } - defer rc.Close() - - // splits the first token of f.Name since it's zip file name - path := filepath.Join(dest, strings.SplitAfterN(f.Name, "/", 2)[1]) - - if f.FileInfo().IsDir() { - err := os.MkdirAll(path, f.Mode()) - if err != nil { - return err - } - } else { - f, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, f.Mode()) - if err != nil { - return err - } - defer f.Close() - - if _, err := io.Copy(f, rc); err != nil { - return err - } - } - - return nil - } - - for _, f := range r.File { - if err := extractFile(f, targetDir); err != nil { - return err - } - } - - // TODO Wrap this function in a validation wrapper from top to bottom - if _, err := util.ValidateTemplate(targetDir); err != nil { - return err - } - - return nil -} - // Download contains the cli-command for downloading templates from github. var Download = &cli.Command{ Use: "download <template-repo> <template-tag>",