<commit_before>#!/usr/bin/env coffee

read     = require 'read'
path     = require 'path'
program  = require 'commander'
Progress = require 'progress'

pkg = require '../../package.json'
App = require '../app'
app = new App process.env.COZY_DESKTOP_DIR
log = global.console

exit = ->
    log.log 'Exiting...'
    setTimeout process.exit, 3500
    app.stopSync ->
        process.exit()

process.on 'SIGINT',  exit
process.on 'SIGTERM', exit
process.on 'SIGUSR1', ->
    app.debugWatchers()

# Helper to get cozy password from user
app.askPassword = (callback) ->
    promptMsg = """
Please enter your password to register your device on your remote Cozy:
"""
    read prompt: promptMsg, silent: true , (err, password) ->
        callback err, password

# Helper for confirmation
app.askConfirmation = (callback) ->
    promptMsg = 'Are your sure? [Y/N]'
    read prompt: promptMsg, (err, response) ->
        callback err, response.toUpperCase() is 'Y'

sync = (mode, args) ->
    log.log "Cozy-desktop v#{pkg.version} started (PID: #{process.pid})"
    if args.logfile?
        app.writeLogsTo args.logfile
    if app.config.setInsecure args.insecure?
        app.events.on 'up-to-date', ->
            log.log 'Your cozy is up to date!'
        app.events.on 'transfer-started', (info) ->
            what = if info.way is 'up' then 'Uploading' else 'Downloading'
            filename = path.basename info.path
            format = "#{what} #{filename} [:bar] :percent :etas"
            if info.size
                options =
                    total: info.size
                    width: 30
                bar = new Progress format, options
                app.events.on info.eventName, (data) ->
                    if data.finished
                        app.events.removeAllListeners info.eventName
                    else
                        bar.tick data.length
            else
                log.log "#{what} #{filename} (unknown size)"
        app.synchronize mode, (err) ->
            process.exit 1 if err
    else<commit_msg>Fix downloading empty file in CLI<commit_after>#!/usr/bin/env coffee

read     = require 'read'
path     = require 'path'
program  = require 'commander'
Progress = require 'progress'

pkg = require '../../package.json'
App = require '../app'
app = new App process.env.COZY_DESKTOP_DIR
log = global.console

exit = ->
    log.log 'Exiting...'
    setTimeout process.exit, 3500
    app.stopSync ->
        process.exit()

process.on 'SIGINT',  exit
process.on 'SIGTERM', exit
process.on 'SIGUSR1', ->
    app.debugWatchers()

# Helper to get cozy password from user
app.askPassword = (callback) ->
    promptMsg = """
Please enter your password to register your device on your remote Cozy:
"""
    read prompt: promptMsg, silent: true , (err, password) ->
        callback err, password

# Helper for confirmation
app.askConfirmation = (callback) ->
    promptMsg = 'Are your sure? [Y/N]'
    read prompt: promptMsg, (err, response) ->
        callback err, response.toUpperCase() is 'Y'

sync = (mode, args) ->
    log.log "Cozy-desktop v#{pkg.version} started (PID: #{process.pid})"
    if args.logfile?
        app.writeLogsTo args.logfile
    if app.config.setInsecure args.insecure?
        app.events.on 'up-to-date', ->
            log.log 'Your cozy is up to date!'
        app.events.on 'transfer-started', (info) ->
            what = if info.way is 'up' then 'Uploading' else 'Downloading'
            filename = path.basename info.path
            format = "#{what} #{filename} [:bar] :percent :etas"
            if +info.size > 0
                options =
                    total: info.size
                    width: 30
                bar = new Progress format, options
                app.events.on info.eventName, (data) ->
                    if data.finished
                        app.events.removeAllListeners info.eventName
                    else
                        bar.tick data.length
            else
                log.log "#{what} #{filename} (unknown size)"
        app.synchronize mode, (err) ->
            process.exit 1 if err
    else
{'fraction_non_alphanumeric': 0.11824569905500364, 'fraction_numerical': 0.004119214926096438, 'mean_word_length': 1.9869753979739508, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3173656', 'n_tokens_mistral': 1228, 'n_tokens_neox': 1186, 'n_words': 359}