Add -u short option for --url and support port number only.
[src/xds/xds-cli.git] / main.go
diff --git a/main.go b/main.go
index b7f110e..3a8671e 100644 (file)
--- a/main.go
+++ b/main.go
@@ -64,8 +64,6 @@ func exitError(code int, f string, a ...interface{}) {
 func main() {
        var earlyDebug []string
 
-       EnvConfFileMap := make(map[string]string)
-
        // Allow to set app name from cli (useful for debugging)
        if AppName == "" {
                AppName = os.Getenv("XDS_APPNAME")
@@ -145,7 +143,7 @@ func main() {
                        Value:  defaultLogLevel,
                },
                cli.StringFlag{
-                       Name:   "url",
+                       Name:   "url, u",
                        EnvVar: "XDS_SERVER_URL",
                        Value:  "localhost:8000",
                        Usage:  "remote XDS server url",
@@ -249,8 +247,15 @@ func XdsConnInit(ctx *cli.Context) error {
 
        // Define HTTP and WS url
        baseURL := ctx.String("url")
-       if !strings.HasPrefix(ctx.String("url"), "http://") {
-               baseURL = "http://" + ctx.String("url")
+
+       // Allow to only set port number
+       if match, _ := regexp.MatchString("^([0-9]+)$", baseURL); match {
+               baseURL = "http://localhost:" + ctx.String("url")
+       }
+
+       // Add http prefix if missing
+       if !strings.HasPrefix(baseURL, "http://") {
+               baseURL = "http://" + baseURL
        }
 
        // Create HTTP client