Added AGL .gitreview file
[src/xds/xds-cli.git] / utils.go
index d632415..3d01346 100644 (file)
--- a/utils.go
+++ b/utils.go
@@ -21,6 +21,8 @@ package main
 import (
        "encoding/json"
        "fmt"
+       "strconv"
+       "strings"
 
        "github.com/franciscocpg/reflectme"
        "github.com/iotbzh/xds-agent/lib/xaapiv1"
@@ -83,6 +85,11 @@ func XdsServerIndexGet() int {
        return 0
 }
 
+// XdsServerComputeURL computes the URL used to access to XDS Server API
+func XdsServerComputeURL(endURL string) string {
+       return "servers/" + strconv.Itoa(XdsServerIndexGet()) + endURL
+}
+
 // ProjectsListGet Get the list of existing projects
 func ProjectsListGet(prjs *[]xaapiv1.ProjectConfig) error {
        var data []byte
@@ -109,3 +116,12 @@ func GetID(ctx *cli.Context) string {
        }
        return id
 }
+
+// Confirm Return true when user answer 'y' or 'yes' to a question
+func Confirm(question string) bool {
+       var answer string
+       fmt.Print(question)
+       fmt.Scanln(&answer)
+       ans := strings.ToLower(strings.TrimSpace(answer))
+       return (ans == "y" || ans == "yes")
+}