Added Copyright headers.
[src/xds/xds-cli.git] / main.go
diff --git a/main.go b/main.go
index 1c75e50..1c0d886 100644 (file)
--- a/main.go
+++ b/main.go
@@ -1,4 +1,23 @@
-// xds-cli: command line tool used to control / interface X(cross) Development System.
+/*
+ * Copyright (C) 2017 "IoT.bzh"
+ * Author Sebastien Douheret <sebastien@iot.bzh>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ *
+ * xds-cli: command line tool used to control / interface X(cross) Development System.
+ */
+
 package main
 
 import (
@@ -37,7 +56,7 @@ var AppSubVersion = "unknown-dev"
 
 // Application details
 const (
-       appCopyright    = "Apache-2.0"
+       appCopyright    = "Copyright (C) 2017 IoT.bzh - Apache-2.0"
        defaultLogLevel = "error"
 )
 
@@ -143,7 +162,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 +266,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