SEBA-672 model update commands
Change-Id: I7fef3a4c1ee5ccb8c33a01f37a772142a82249c1
diff --git a/commands/common.go b/commands/common.go
index 9461f99..93c1b5d 100644
--- a/commands/common.go
+++ b/commands/common.go
@@ -16,6 +16,7 @@
package commands
import (
+ "bufio"
b64 "encoding/base64"
"fmt"
"github.com/fullstorydev/grpcurl"
@@ -23,6 +24,9 @@
"golang.org/x/net/context"
"google.golang.org/grpc"
reflectpb "google.golang.org/grpc/reflection/grpc_reflection_v1alpha"
+ "log"
+ "os"
+ "strings"
)
func GenerateHeaders() []string {
@@ -62,3 +66,30 @@
fmt.Printf(format, args...)
}
}
+
+// Print a confirmation prompt and get a response from the user
+func Confirmf(format string, args ...interface{}) bool {
+ if GlobalOptions.Yes {
+ return true
+ }
+
+ reader := bufio.NewReader(os.Stdin)
+
+ for {
+ msg := fmt.Sprintf(format, args...)
+ fmt.Print(msg)
+
+ response, err := reader.ReadString('\n')
+ if err != nil {
+ log.Fatal(err)
+ }
+
+ response = strings.ToLower(strings.TrimSpace(response))
+
+ if response == "y" || response == "yes" {
+ return true
+ } else if response == "n" || response == "no" {
+ return false
+ }
+ }
+}