Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update command merged into version #217

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions pkg/cmd/root/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (

"github.com/litmuschaos/litmusctl/pkg/cmd/run"
"github.com/litmuschaos/litmusctl/pkg/cmd/save"
"github.com/litmuschaos/litmusctl/pkg/cmd/update"

"github.com/litmuschaos/litmusctl/pkg/cmd/connect"
"github.com/litmuschaos/litmusctl/pkg/cmd/delete"
Expand Down Expand Up @@ -77,7 +76,6 @@ func init() {
rootCmd.AddCommand(save.SaveCmd)
rootCmd.AddCommand(run.RunCmd)
rootCmd.AddCommand(list.ListCmd)
rootCmd.AddCommand(update.UpdateCmd)

// Here you will define your flags and configuration settings.
// Cobra supports persistent flags, which, if defined here,
Expand Down
98 changes: 0 additions & 98 deletions pkg/cmd/update/update.go

This file was deleted.

95 changes: 94 additions & 1 deletion pkg/cmd/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,14 @@ limitations under the License.
package version

import (
"io"
"net/http"
"os"
"os/exec"
"runtime"

"github.com/litmuschaos/litmusctl/pkg/utils"

homedir "github.com/mitchellh/go-homedir"
"github.com/spf13/cobra"
)

Expand All @@ -44,3 +48,92 @@ var VersionCmd = &cobra.Command{
utils.White_B.Print("]\n")
},
}

var UpdateCmd = &cobra.Command{
Use: "update",
Short: "Changes the version of litmusctl",
Args: cobra.ExactArgs(1),
Long: ``,
Run: func(cmd *cobra.Command, args []string) {
updateVersion := args[0]
homeDir, err := homedir.Dir()
if err != nil {
utils.PrintError(err)
}

var assetURL string = "https://litmusctl-production-bucket.s3.amazonaws.com/"
var binaryName string = "litmusctl"
switch runtime.GOOS {
case "windows":
if runtime.GOARCH == "386" {
binaryName += "-windows-386-" + updateVersion + ".tar.gz"
assetURL += binaryName
} else if runtime.GOARCH == "amd64" {
binaryName += "-windows-amd64-" + updateVersion + ".tar.gz"
assetURL += binaryName
} else {
binaryName += "-windows-arm64-" + updateVersion + ".tar.gz"
assetURL += binaryName
}
case "linux":
if runtime.GOARCH == "arm64" {
binaryName += "-linux-arm64-" + updateVersion + ".tar.gz"
assetURL += binaryName
} else if runtime.GOARCH == "amd64" {
binaryName += "-linux-amd64-" + updateVersion + ".tar.gz"
assetURL += binaryName
} else if runtime.GOARCH == "arm" {
binaryName += "-linux-arm-" + updateVersion + ".tar.gz"
assetURL += binaryName
} else {
binaryName += "-linux-386-" + updateVersion + ".tar.gz"
assetURL += binaryName
}
case "darwin":
if runtime.GOARCH == "amd64" {
binaryName += "-darwin-amd64-" + updateVersion + ".tar.gz"
assetURL += binaryName
}
}

utils.White.Print("Downloading:\n")

resp2, err := http.Get(assetURL)
if err != nil {
utils.PrintError(err)
}

tempFile, err := os.CreateTemp("", binaryName)
if err != nil {
utils.PrintError(err)
return
}
defer os.Remove(tempFile.Name())

_, err = io.Copy(tempFile, resp2.Body)
if err != nil {
utils.PrintError(err)
return
}
utils.White_B.Print("OK\n")

tempFile.Close()

tarCmd := exec.Command("tar", "xzf", tempFile.Name(), "-C", homeDir)
tarCmd.Stdout = os.Stdout
tarCmd.Stderr = os.Stderr

utils.White_B.Print("Extracting binary...\n")
err = tarCmd.Run()
if err != nil {
utils.PrintError(err)
return
}

utils.White_B.Print("Binary extracted successfully\n")
},
}

func init() {
VersionCmd.AddCommand(UpdateCmd)
}
Loading