0001    /**
0002     * Copyright IBM Corporation 2016
0003     *
0004     * Licensed under the Apache License, Version 2.0 (the "License");
0005     * you may not use this file except in compliance with the License.
0006     * You may obtain a copy of the License at
0007     *
0008     * http://www.apache.org/licenses/LICENSE-2.0
0009     *
0010     * Unless required by applicable law or agreed to in writing, software
0011     * distributed under the License is distributed on an "AS IS" BASIS,
0012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0013     * See the License for the specific language governing permissions and
0014     * limitations under the License.
0015     **/
0016    
0017    public func parseAddress() -> Address {
0018      let args = Array(Process.arguments[1..<Process.arguments.count])
0019      var port = 9080 // default port
0020      var ip = "0.0.0.0" // default ip
0021      if args.count == 2 && args[0] == "-bind" {
0022        let tokens = args[1].bridge().componentsSeparatedByString(":")
0023        if (tokens.count == 2) {
0024          ip = tokens[0]
0025          if let portNumber = Int(tokens[1]) {
0026            port = portNumber
0027          }
0028        }
0029      }
0030      let address = Address(ip: ip, port: UInt16(port))
0031      return address
0032    }
0033