diff --git a/cmd/spawn/local-interchain.go b/cmd/spawn/local-interchain.go index 14e0f4d0..03141cf9 100644 --- a/cmd/spawn/local-interchain.go +++ b/cmd/spawn/local-interchain.go @@ -2,34 +2,20 @@ package main import ( "fmt" - "io" - "net/http" "os" "os/exec" "path" - "strings" - "time" - "github.com/schollz/progressbar/v3" "github.com/spf13/cobra" "gitub.com/strangelove-ventures/spawn/spawn" ) -var ( - LocalICDefaultVersion = "v8.1.0" - LocalICURL = "https://github.com/strangelove-ventures/interchaintest/releases/download/" + LocalICDefaultVersion + "/local-ic" -) - const ( - FlagVersionOverride = "version" - FlagForceDownload = "download" - FlagLocationPath = "print-location" + FlagLocationPath = "print-location" ) func init() { - LocalICCmd.Flags().String(FlagVersionOverride, LocalICDefaultVersion, "change the local-ic version to use") - LocalICCmd.Flags().Bool(FlagForceDownload, false, "force download of local-ic") LocalICCmd.Flags().Bool(FlagLocationPath, false, "print the location of local-ic binary") } @@ -37,21 +23,18 @@ func init() { // make install && ICTEST_HOME=./simapp spawn local-ic start testnet // make install && cd simapp && spawn local-ic start testnet // --- -// TODO: Do something like `curl https://get.ignite.com/cli! | bash`? just with windows support for path var LocalICCmd = &cobra.Command{ Use: "local-ic", Short: "Local Interchain", - Long: fmt.Sprintf("Download Local Interchain from %s", LocalICURL), + Long: "Wrapper for Local Interchain. Download with `make get-localic`", // Args: cobra. Run: func(cmd *cobra.Command, args []string) { - version, _ := cmd.Flags().GetString(FlagVersionOverride) - forceDownload, _ := cmd.Flags().GetBool(FlagForceDownload) debugBinaryLoc, _ := cmd.Flags().GetBool(FlagLocationPath) loc := whereIsLocalICInstalled() - if (forceDownload || loc == "") && version != "" { - downloadBin(version) - loc = whereIsLocalICInstalled() + if loc == "" { + fmt.Println("local-ic not found. Please run `make get-localic`") + return } if debugBinaryLoc { @@ -89,76 +72,3 @@ func whereIsLocalICInstalled() string { return "" } - -func downloadBin(version string) error { - file := "local-ic" - - f, err := os.Create(file) - if err != nil { - return err - } - defer f.Close() - - currentDir, err := os.Getwd() - if err != nil { - return err - } - - if version != "" && version != LocalICDefaultVersion { - if version[0] != 'v' { - version = "v" + version - } - - LocalICURL = strings.ReplaceAll(LocalICURL, LocalICDefaultVersion, version) - } - - dir := path.Join(currentDir, "bin") - if err := os.MkdirAll(dir, os.ModePerm); err != nil { - return err - } - - filePath := path.Join(dir, file) - - if err := downloadWithProgress(filePath, LocalICURL); err != nil { - return err - } - - if err := os.Chmod(file, 0755); err != nil { - return err - } - - fmt.Printf("✅ Local Interchain Downloaded to %s\n", filePath) - return nil -} - -func downloadWithProgress(destinationPath, downloadUrl string) error { - req, err := http.NewRequest("GET", downloadUrl, nil) - if err != nil { - return err - } - - resp, err := http.DefaultClient.Do(req) - if err != nil { - return err - } - - defer resp.Body.Close() - - f, err := os.OpenFile(destinationPath, os.O_CREATE|os.O_WRONLY, 0644) - if err != nil { - return err - } - - bar := progressbar.NewOptions64( - resp.ContentLength, - progressbar.OptionSetDescription("⏳ Downloading Local-Interchain..."), - progressbar.OptionSetWidth(50), - progressbar.OptionThrottle(0*time.Millisecond), - progressbar.OptionOnCompletion(func() { - fmt.Fprint(os.Stderr, "\n") - }), - ) - - io.Copy(io.MultiWriter(f, bar), resp.Body) - return nil -} diff --git a/go.mod b/go.mod index 7fa754f0..d600293e 100644 --- a/go.mod +++ b/go.mod @@ -6,19 +6,14 @@ replace github.com/strangelove-ventures/simapp => ./simapp require ( github.com/cosmos/btcutil v1.0.5 - github.com/schollz/progressbar/v3 v3.14.1 + github.com/manifoldco/promptui v0.9.0 github.com/spf13/cobra v1.8.0 + github.com/spf13/pflag v1.0.5 github.com/strangelove-ventures/simapp v0.0.0-00000000-000000000000 - golang.org/x/text v0.14.0 ) require ( github.com/chzyer/readline v1.5.1 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect - github.com/manifoldco/promptui v0.9.0 // indirect - github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db // indirect - github.com/rivo/uniseg v0.4.7 // indirect - github.com/spf13/pflag v1.0.5 // indirect golang.org/x/sys v0.17.0 // indirect - golang.org/x/term v0.17.0 // indirect ) diff --git a/go.sum b/go.sum index df54f1df..7010aa3d 100644 --- a/go.sum +++ b/go.sum @@ -1,53 +1,27 @@ github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= +github.com/chzyer/logex v1.2.1 h1:XHDu3E6q+gdHgsdTPH6ImJMIp436vR6MPtH8gP05QzM= github.com/chzyer/logex v1.2.1/go.mod h1:JLbx6lG2kDbNRFnfkgvh4eRJRPX1QCoOIWomwysCBrQ= github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= github.com/chzyer/readline v1.5.1 h1:upd/6fQk4src78LMRzh5vItIt361/o4uq553V8B5sGI= github.com/chzyer/readline v1.5.1/go.mod h1:Eh+b79XXUwfKfcPLepksvw2tcLE/Ct21YObkaSkeBlk= github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= +github.com/chzyer/test v1.0.0 h1:p3BQDXSxOhOG0P9z6/hGnII4LGiEPOYBhs8asl/fC04= github.com/chzyer/test v1.0.0/go.mod h1:2JlltgoNkt4TW/z9V/IzDdFaMTM2JPIi26O1pF38GC8= github.com/cosmos/btcutil v1.0.5 h1:t+ZFcX77LpKtDBhjucvnOH8C2l2ioGsBNEQ3jef8xFk= github.com/cosmos/btcutil v1.0.5/go.mod h1:IyB7iuqZMJlthe2tkIFL33xPyzbFYP0XVdS8P5lUPis= github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= -github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= -github.com/k0kubun/go-ansi v0.0.0-20180517002512-3bf9e2903213/go.mod h1:vNUNkEQ1e29fT/6vq2aBdFsgNPmy8qMdSay1npru+Sw= github.com/manifoldco/promptui v0.9.0 h1:3V4HzJk1TtXW1MTZMP7mdlwbBpIinw3HztaIlYthEiA= github.com/manifoldco/promptui v0.9.0/go.mod h1:ka04sppxSGFAtxX0qhlYQjISsg9mR4GWtQEhdbn6Pgg= -github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= -github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db h1:62I3jR2EmQ4l5rM/4FEfDWcRD+abF5XlKShorW5LRoQ= -github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db/go.mod h1:l0dey0ia/Uv7NcFFVbCLtqEBQbrT4OCwCSKTEv6enCw= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= -github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/rivo/uniseg v0.4.4/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= -github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ= -github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= -github.com/schollz/progressbar/v3 v3.14.1 h1:VD+MJPCr4s3wdhTc7OEJ/Z3dAeBzJ7yKH/P4lC5yRTI= -github.com/schollz/progressbar/v3 v3.14.1/go.mod h1:Zc9xXneTzWXF81TGoqL71u0sBPjULtEHYtj/WVgVy8E= github.com/spf13/cobra v1.8.0 h1:7aJaZx1B85qltLMc546zn58BxxfZdR/W22ej9CFoEf0= github.com/spf13/cobra v1.8.0/go.mod h1:WXLWApfZ71AjXPya3WOlMsY9yMs7YeiHhFVlvLyhcho= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= -github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= -github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= golang.org/x/sys v0.0.0-20181122145206-62eef0e2fa9b/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y= golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/term v0.14.0/go.mod h1:TySc+nGkYR6qt8km8wUhuFRTVSMIX3XPR58y2lC8vww= -golang.org/x/term v0.17.0 h1:mkTF7LCd6WGJNL3K1Ad7kwxNfYAW6a8a8QqtMblp/4U= -golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk= -golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= -golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=