diff --git a/client/config.go b/client/config.go index 7beac520..495b6f31 100644 --- a/client/config.go +++ b/client/config.go @@ -152,7 +152,10 @@ func LoadConfig() (config *CliConfig, err error) { fmt.Printf("We have been redirected to : %s\n", finalURL) fmt.Printf("Replace current url (%s) with the new one ? [Y/n] ", config.URL) - ok, _ := common.AskConfirmation(true) + ok, err := common.AskConfirmation(true) + if err != nil { + return nil, fmt.Errorf("Unable to ask for confirmation : %s", err) + } if ok { config.URL = strings.TrimSuffix(finalURL, "/") } @@ -160,7 +163,10 @@ func LoadConfig() (config *CliConfig, err error) { // Enable client updates ? fmt.Println("Do you want to enable client auto update ? [Y/n] ") - ok, _ := common.AskConfirmation(true) + ok, err := common.AskConfirmation(true) + if err != nil { + return nil, fmt.Errorf("Unable to ask for confirmation : %s", err) + } if ok { config.AutoUpdate = true } diff --git a/client/update.go b/client/update.go index df688ac8..e09088a4 100644 --- a/client/update.go +++ b/client/update.go @@ -84,11 +84,14 @@ func update(client *plik.Client, updateFlag bool) (err error) { } else { fmt.Printf("Update Plik client to match server version ? [Y/n] ") } - if ok, _ := common.AskConfirmation(true); !ok { + if ok, err := common.AskConfirmation(true); err != nil || !ok { + if err != nil { + return fmt.Errorf("Unable to ask for confirmation : %s", err) + } if updateFlag { os.Exit(0) } - return + return nil } // Display release notes @@ -147,7 +150,10 @@ func update(client *plik.Client, updateFlag bool) (err error) { // Ask to display the release notes fmt.Printf("Do you want to browse the release notes of version %s ? [Y/n] ", release.Name) - if ok, _ := common.AskConfirmation(true); !ok { + if ok, err := common.AskConfirmation(true); err != nil || !ok { + if err != nil { + return fmt.Errorf("Unable to ask for confirmation : %s", err) + } continue } @@ -159,7 +165,10 @@ func update(client *plik.Client, updateFlag bool) (err error) { // Let user review the last release notes and ask to confirm update if release.Name == newVersion { fmt.Printf("\nUpdate Plik client from %s to %s ? [Y/n] ", currentVersion, newVersion) - if ok, _ := common.AskConfirmation(true); !ok { + if ok, err := common.AskConfirmation(true); err != nil || !ok { + if err != nil { + return fmt.Errorf("Unable to ask for confirmation : %s", err) + } if updateFlag { os.Exit(0) } diff --git a/server/cmd/file.go b/server/cmd/file.go index badd9ab7..c7a7b697 100644 --- a/server/cmd/file.go +++ b/server/cmd/file.go @@ -114,7 +114,11 @@ func deleteFiles(cmd *cobra.Command, args []string) { // Ask confirmation fmt.Printf("Do you really want to remove this file %s %s ? [y/N]\n", file.ID, file.Name) - ok, _ := common.AskConfirmation(false) + ok, err := common.AskConfirmation(false) + if err != nil { + fmt.Printf("Unable to ask for confirmation : %s", err) + os.Exit(1) + } if !ok { os.Exit(0) } @@ -128,12 +132,16 @@ func deleteFiles(cmd *cobra.Command, args []string) { // Ask confirmation fmt.Printf("Do you really want to remove this upload %s ? [y/N]\n", fileParams.uploadID) - ok, _ := common.AskConfirmation(false) + ok, err := common.AskConfirmation(false) + if err != nil { + fmt.Printf("Unable to ask for confirmation : %s", err) + os.Exit(1) + } if !ok { os.Exit(0) } - err := metadataBackend.DeleteUpload(fileParams.uploadID) + err = metadataBackend.DeleteUpload(fileParams.uploadID) if err != nil { fmt.Printf("Unable to get upload files : %s\n", err) os.Exit(1) @@ -142,7 +150,11 @@ func deleteFiles(cmd *cobra.Command, args []string) { // Ask confirmation fmt.Printf("Do you really want to remove ALL uploads ? [y/N]\n") - ok, _ := common.AskConfirmation(false) + ok, err := common.AskConfirmation(false) + if err != nil { + fmt.Printf("Unable to ask for confirmation : %s", err) + os.Exit(1) + } if !ok { os.Exit(0) } @@ -150,7 +162,7 @@ func deleteFiles(cmd *cobra.Command, args []string) { deleteUpload := func(upload *common.Upload) error { return metadataBackend.DeleteUpload(upload.ID) } - err := metadataBackend.ForEachUpload(deleteUpload) + err = metadataBackend.ForEachUpload(deleteUpload) if err != nil { fmt.Printf("Unable to delete uploads : %s\n", err) os.Exit(1) diff --git a/server/cmd/user.go b/server/cmd/user.go index 53759a8c..9f2c7c3d 100644 --- a/server/cmd/user.go +++ b/server/cmd/user.go @@ -279,7 +279,11 @@ func deleteUser(cmd *cobra.Command, args []string) { // Ask confirmation fmt.Printf("Do you really want to delete this user %s and all its uploads ? [y/N]\n", userID) - ok, _ := common.AskConfirmation(false) + ok, err := common.AskConfirmation(false) + if err != nil { + fmt.Printf("Unable to ask for confirmation : %s", err) + os.Exit(1) + } if !ok { os.Exit(0) } diff --git a/server/common/utils.go b/server/common/utils.go index 3f30bfc6..48de426a 100644 --- a/server/common/utils.go +++ b/server/common/utils.go @@ -83,6 +83,9 @@ func AskConfirmation(defaultValue bool) (bool, error) { var input string _, err := fmt.Scanln(&input) if err != nil { + if err.Error() == "unexpected newline" { + return defaultValue, nil + } return false, err }