X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=main.go;fp=main.go;h=3a8671ebc3115f235f1d2edd81fc4ac3baebda47;hb=b504ab8b02e2891c33e9883a4bb1a3e0f90b2b1e;hp=1c75e509bd8940908b63c25da39f5968635befc6;hpb=75416fe01aa98b53c57315a050fc58f0879a238d;p=src%2Fxds%2Fxds-cli.git diff --git a/main.go b/main.go index 1c75e50..3a8671e 100644 --- a/main.go +++ b/main.go @@ -143,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", @@ -247,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