             results.rows.map (row) ->
                 console.log row.doc
 
+
 # Disaply all docs returned by a given query.
 displayQuery = (query) ->
     db = require('./backend/db').db

# Start database sync process and setup file change watcher.
sync = (args) ->

    # Watch local changes
    if args.twoway
        filesystem.watchChanges true, true

    config = config.getConfig()

    if not (config.deviceName? and config.url? and config.path?)
        log.error """
No configuration found, please run add-remote-cozy command before running a synchronization.
"""
    else

        pouch.addAllFilters ->
            # Replicate databases

    console.log JSON.stringify config.config, null, 2


resetDatabase = ->
    log.info "Recreates the local database..."
    pouch.resetDatabase ->
        log.info "Database recreated"


program
    .command 'add-remote-cozy <url> <devicename> <syncPath>'
    .description 'Configure current device to sync with given cozy'
    .option '-d, --deviceName [deviceName]', 'device name to deal with'
    .action addRemote

program
    .command 'remove-remote-cozy'
    .description 'Unsync current device with its remote cozy'
    .action removeRemote

program
    .command 'sync'
    .description 'Sync databases, apply and/or watch changes'
    .option('-r, --readonly',
            'only apply remote changes to local folder')
    .option('-f, --force',
            'Run sync from the beginning of all the Cozy changes.')
    .action sync

program
    .command 'reset-database'
    .description 'Recreates the local database'
    .action resetDatabase

program
    .command 'display-database'
    .description 'Display database content'
    .action displayDatabase

program
    .command 'display-query <query>'
    .description 'Display database query result'
    .action displayQuery

program
    .command 'display-config'
    .description 'Display device configuration and exit'
    .action displayConfig

program
    .command "*"
    .description "Display help message for an unknown command."
    .action ->
        log.info 'Unknown command, run "cozy-desktop --help"' + \
                 ' to know the list of available commands.'

program
    .version pkg.version


if not module.parent
