     dbPath: path.join defaultDir, 'db'
     config: require configPath or devices: []
 
+    # Return config related to device name.
     getConfig: (deviceName) ->
         deviceName = @getDeviceName() unless deviceName?
 

            log.error "Device not set locally: #{deviceName}"
            process.exit 1

    getDeviceName: () ->
        # Get the argument after -d or --deviceName
        for arg, index in process.argv
            if arg is '-d' or arg is '--deviceName'
                return process.argv[index + 1]

        # Or return the first device name
        return Object.keys(@config.devices)[0]

    addRemoteCozy: (options) ->
        @config.devices ?= {}
        @config.devices[options.deviceName] = options
        @saveConfig()

    removeRemoteCozy: (deviceName) ->
        @config.devices ?= {}
        delete @config.devices[deviceName]
        @saveConfig()

    saveConfig: ->
        fs.writeFileSync configPath, JSON.stringify @config, null, 2

log     = require('printit')
          prefix: 'Data Proxy | config'

# Create config file if it doesn't exist.
defaultDir = path.join path.homedir(), '.cozy-data-proxy'
configPath = path.join defaultDir, './config.json'
fs.ensureFileSync configPath
