 async = require 'async'
 path  = require 'path-extra'
 os    = require 'os'
+url   = require 'url'
 log   = require('printit')
     prefix: 'Cozy Desktop  '
 

            @askPassword,
            (password, next) ->
                options =
                    url: url
                    deviceName: deviceName
                    password: password
                Devices.registerDevice options, next


    # Register current device to remote Cozy and then save related informations
    # to the config file
    addRemote: (cozyUrl, syncPath, deviceName, callback) =>
        parsed = url.parse cozyUrl
        parsed.protocol ?= 'https:'
        cozyUrl = url.format parsed
        unless parsed.protocol in ['http:', 'https:'] and parsed.hostname
            log.warn "Your URL looks invalid: #{cozyUrl}"
            callback? err
            return
        deviceName ?= os.hostname() or 'desktop'
