From b175ad0290f2939c8c997680a5a3889172387d30 Mon Sep 17 00:00:00 2001 From: "Ali R. Vahdati" <3798865+kavir1698@users.noreply.github.com> Date: Tue, 9 Apr 2024 11:19:38 +0200 Subject: [PATCH] Remove interactive flag from CheckForNewVersion --- cmd/datasetArchiver/main.go | 2 +- cmd/datasetCleaner/main.go | 2 +- cmd/datasetGetProposal/main.go | 2 +- cmd/datasetIngestor/main.go | 2 +- cmd/datasetRetriever/main.go | 2 +- datasetUtils/checkForNewVersion.go | 33 +------------------------ datasetUtils/checkForNewVersion_test.go | 32 +----------------------- 7 files changed, 7 insertions(+), 68 deletions(-) diff --git a/cmd/datasetArchiver/main.go b/cmd/datasetArchiver/main.go index d5ef8b5..0bc1a5b 100644 --- a/cmd/datasetArchiver/main.go +++ b/cmd/datasetArchiver/main.go @@ -58,7 +58,7 @@ func main() { } // check for program version only if running interactively - datasetUtils.CheckForNewVersion(client, APP, VERSION, !*nonInteractiveFlag, datasetUtils.StdinUserInput{}) + datasetUtils.CheckForNewVersion(client, APP, VERSION) if *testenvFlag { APIServer = TEST_API_SERVER diff --git a/cmd/datasetCleaner/main.go b/cmd/datasetCleaner/main.go index 76da155..2cc1ffc 100644 --- a/cmd/datasetCleaner/main.go +++ b/cmd/datasetCleaner/main.go @@ -82,7 +82,7 @@ func main() { } // check for program version only if running interactively - datasetUtils.CheckForNewVersion(client, APP, VERSION, !*nonInteractiveFlag, datasetUtils.StdinUserInput{}) + datasetUtils.CheckForNewVersion(client, APP, VERSION) datasetUtils.CheckForServiceAvailability(client, *testenvFlag, true) //} diff --git a/cmd/datasetGetProposal/main.go b/cmd/datasetGetProposal/main.go index 529217f..1991ea8 100644 --- a/cmd/datasetGetProposal/main.go +++ b/cmd/datasetGetProposal/main.go @@ -53,7 +53,7 @@ func main() { } // check for program version only if running interactively - datasetUtils.CheckForNewVersion(client, APP, VERSION, true, datasetUtils.StdinUserInput{}) + datasetUtils.CheckForNewVersion(client, APP, VERSION) if *testenvFlag { APIServer = TEST_API_SERVER diff --git a/cmd/datasetIngestor/main.go b/cmd/datasetIngestor/main.go index d453798..5d2c57d 100644 --- a/cmd/datasetIngestor/main.go +++ b/cmd/datasetIngestor/main.go @@ -141,7 +141,7 @@ func main() { } // check for program version only if running interactively - datasetUtils.CheckForNewVersion(client, APP, VERSION, !*noninteractiveFlag, datasetUtils.StdinUserInput{}) + datasetUtils.CheckForNewVersion(client, APP, VERSION) datasetUtils.CheckForServiceAvailability(client, *testenvFlag, *autoarchiveFlag) //} diff --git a/cmd/datasetRetriever/main.go b/cmd/datasetRetriever/main.go index 7613f20..47791b8 100644 --- a/cmd/datasetRetriever/main.go +++ b/cmd/datasetRetriever/main.go @@ -74,7 +74,7 @@ func main() { return } - datasetUtils.CheckForNewVersion(client, APP, VERSION, true, datasetUtils.StdinUserInput{}) + datasetUtils.CheckForNewVersion(client, APP, VERSION) var env string if *testenvFlag { diff --git a/datasetUtils/checkForNewVersion.go b/datasetUtils/checkForNewVersion.go index 97edbb7..c516180 100644 --- a/datasetUtils/checkForNewVersion.go +++ b/datasetUtils/checkForNewVersion.go @@ -52,7 +52,7 @@ func generateDownloadURL(deployLocation, latestVersion, osName string) string { return fmt.Sprintf("%s/v%s/scicat-cli_.%s_%s_x86_64.tar.gz", deployLocation, latestVersion, latestVersion, strings.Title(osName)) } -func CheckForNewVersion(client *http.Client, APP string, VERSION string, interactiveFlag bool, userInput UserInput) { +func CheckForNewVersion(client *http.Client, APP string, VERSION string) { // avoid checking for new version in test mode if os.Getenv("TEST_MODE") == "true" { return @@ -80,16 +80,6 @@ func CheckForNewVersion(client *http.Client, APP string, VERSION string, interac // Generate the download URL downloadURL := generateDownloadURL(DeployLocation, latestVersion, osName) - // Split the versions into parts - currentParts := strings.Split(VERSION, ".") - latestParts := strings.Split(latestVersion, ".") - - // Convert the major and minor parts to integers - currentMajor, _ := strconv.Atoi(currentParts[0]) - currentMinor, _ := strconv.Atoi(currentParts[1]) - latestMajor, _ := strconv.Atoi(latestParts[0]) - latestMinor, _ := strconv.Atoi(latestParts[1]) - if version.Compare(latestVersion, VERSION, ">") { // Notify an update if the version has changed log.Println("You should upgrade to a newer version") @@ -105,26 +95,5 @@ func CheckForNewVersion(client *http.Client, APP string, VERSION string, interac } else { log.Println("Your version of this program is up-to-date") } - if interactiveFlag && (latestMajor > currentMajor || latestMinor > currentMinor) { - log.Print("Do you want to continue with current version (y/N) ? ") - continueyn, err := userInput.ReadLine() - if err != nil { - log.Printf("Warning: Failed to read user input: %v\n", err) - } else if strings.TrimSpace(continueyn) != "y" { - log.Println("Warning: Execution stopped, please update the program now.") - } - } return } - -// UserInput is an interface that defines a method to read a line of input. We use this so that we can test interactive mode. -type UserInput interface { - ReadLine() (string, error) -} - -type StdinUserInput struct{} - -func (StdinUserInput) ReadLine() (string, error) { - reader := bufio.NewReader(os.Stdin) - return reader.ReadString('\n') -} diff --git a/datasetUtils/checkForNewVersion_test.go b/datasetUtils/checkForNewVersion_test.go index aa0141c..cf6110f 100644 --- a/datasetUtils/checkForNewVersion_test.go +++ b/datasetUtils/checkForNewVersion_test.go @@ -82,48 +82,18 @@ func TestCheckForNewVersion(t *testing.T) { currentVersion string mockResponse string expectedLog string - interactiveFlag bool - userInput string }{ { name: "New version available, non-interactive mode", currentVersion: "0.9.0", mockResponse: `{"tag_name": "v1.0.0"}`, expectedLog: "You should upgrade to a newer version", - interactiveFlag: false, - userInput: "y\n", }, { name: "No new version available, non-interactive mode", currentVersion: "1.0.0", mockResponse: `{"tag_name": "v1.0.0"}`, expectedLog: "Your version of this program is up-to-date", - interactiveFlag: false, - userInput: "y\n", - }, - { - name: "New version available, interactive mode", - currentVersion: "0.9.0", - mockResponse: `{"tag_name": "v1.0.0"}`, - expectedLog: "You should upgrade to a newer version", - interactiveFlag: true, - userInput: "y\n", - }, - { - name: "New version available, interactive mode, no upgrade", - currentVersion: "0.9.0", - mockResponse: `{"tag_name": "v1.0.0"}`, - expectedLog: "Warning: Execution stopped, please update the program now.", - interactiveFlag: true, - userInput: "n\n", - }, - { - name: "New path available, interactive mode", - currentVersion: "0.9.0", - mockResponse: `{"tag_name": "v0.9.1"}`, - expectedLog: "You should upgrade to a newer version", - interactiveFlag: true, - userInput: "y\n", }, } @@ -145,7 +115,7 @@ func TestCheckForNewVersion(t *testing.T) { client := server.Client() // Call CheckForNewVersion - CheckForNewVersion(client, "test", tt.currentVersion, tt.interactiveFlag, MockUserInput{Input: tt.userInput}) + CheckForNewVersion(client, "test", tt.currentVersion) // Check the log output logOutput := getLogOutput()