 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

    dbPath: path.join defaultDir, 'db'
    config: require configPath or devices: []

    getConfig: (deviceName) ->
        deviceName = @getDeviceName() unless deviceName?


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

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

        return Object.keys(@config.devices)[0]

    # Add remote configuration for a given device name.
    addRemoteCozy: (options) ->
        @config.devices ?= {}
        @config.devices[options.deviceName] = options
        @saveConfig()

    # Remove remote configuration for a given device name.
    removeRemoteCozy: (deviceName) ->
        @config.devices ?= {}
        delete @config.devices[deviceName]
        @saveConfig()

    # Save configuration to file system.
    saveConfig: ->
        fs.writeFileSync configPath, JSON.stringify @config, null, 2
