From: Sebastien Douheret Date: Thu, 30 Nov 2017 13:29:35 +0000 (+0100) Subject: Add -u short option for --url and support port number only. X-Git-Tag: v0.1.0~2 X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?p=src%2Fxds%2Fxds-cli.git;a=commitdiff_plain;h=b504ab8b02e2891c33e9883a4bb1a3e0f90b2b1e Add -u short option for --url and support port number only. Signed-off-by: Sebastien Douheret --- diff --git a/.vscode/settings.json b/.vscode/settings.json index 8427f3c..7e90d15 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -23,6 +23,7 @@ // Words to add to dictionary for a workspace. "cSpell.words": [ "apiv", "iosk", "zhouhui", "ldflags", "socketio", "xdsconfig", "sdkid", - "godotenv", "crosssdk", "prjs", "xaapiv", "urfave" + "godotenv", "crosssdk", "prjs", "xaapiv", "urfave", "sebd", "golib", + "joho", "XDSAGENT" ] } diff --git a/cmd-misc.go b/cmd-misc.go index 1a5d6d4..e8fe61f 100644 --- a/cmd-misc.go +++ b/cmd-misc.go @@ -39,7 +39,8 @@ func xdsVersion(ctx *cli.Context) error { } writer := NewTableWriter() - fmt.Fprintln(writer, "Agent ID:\t", ver.Client.ID) + fmt.Fprintln(writer, "Agent:") + fmt.Fprintln(writer, " ID:\t", ver.Client.ID) v := ver.Client.Version if verbose { v += " (" + ver.Client.VersionGitTag + ")" @@ -50,7 +51,8 @@ func xdsVersion(ctx *cli.Context) error { } for _, svr := range ver.Server { - fmt.Fprintln(writer, "Server ID:\t", svr.ID) + fmt.Fprintln(writer, "Server:") + fmt.Fprintln(writer, " ID:\t", svr.ID) v = svr.Version if verbose { v += " (" + svr.VersionGitTag + ")" 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