<commit_before>User = require './server/models/user'
CozyInstance = require './server/models/cozyinstance'
Application = require './server/models/application'

runCmd = ->
    switch process.argv[2]
        when 'cleanuser'
            User.destroyAll (error) ->
                if error
                     console.log error.stack
                     console.log "Cleaning Users failed."
                else
                     console.log "All users are removed."
            break
        when 'cleanapps'
            Application.destroyAll (error) ->
                 if error
                     console.log error.stack
                     console.log "Cleaning Applications failed."
                 else
                     console.log "All applications and users are removed."
            break
        when 'cleandb'
            destroyApplications = ->
                Application.destroyAll (error) ->
                     if error
                         console.log error.stack
                         console.log "Cleaning Applications failed."
                     else
                         console.log "All applications and users are removed."

            destroyInstances = ->
                CozyInstance.destroyAll (error) ->
                    if error
                         console.log error.stack
                         console.log "Cleaning instances failed."
                    else
                         destroyApplications()

            destroyUsers = ->
                User.destroyAll (error) ->
                    if error
                         console.log error.stack
                         console.log "Cleaning Users failed."
                    else
                         destroyInstances()

            destroyUsers()
            break

        when 'set_help_url'
            url = process.argv[3]
            CozyInstance.all (err, instances) ->
                if err
                    console.log err
                else if instances.length is 0
                    console.log "No instance found"
                    process.exit 1
                else
                    instance = instances[0]
                    instance.helpUrl = url
                    instance.save (err) ->
                        if err then console.log err
                        else console.log "Help url name set with #{url}"
                        process.exit 0
            break

        when 'setdomain'
            domain = process.argv[3]
            CozyInstance.all (err, instances) ->
                if err
                    console.log err
                else if instances.length is 0
                    CozyInstance.create domain: domain, (err) ->
                        if err then console.log err
                        else console.log "Domain name set with #{domain}"
                        process.exit 0
                else
                    instance = instances[0]
                    instance.domain = domain
                    instance.save (err) ->
                        if err then console.log err
                        else console.log "Domain name set with #{domain}"
                        process.exit 0
            break

        when 'getdomain'
            CozyInstance.all (err, instances) ->
                if err
                    console.log '{domain:"error"}'
                    process.exit 1
                else if instances.length is 0
                    console.log '{domain:null}'
                    process.exit 0
                else
                    console.log "{domain:\"#{instances[0].domain}}\""
                    process.exit 0
            break

runCmd()
<commit_msg>set error exit code to 1 when set domain fails<commit_after>User = require './server/models/user'
CozyInstance = require './server/models/cozyinstance'
Application = require './server/models/application'

runCmd = ->
    switch process.argv[2]
        when 'cleanuser'
            User.destroyAll (error) ->
                if error
                     console.log error.stack
                     console.log "Cleaning Users failed."
                else
                     console.log "All users are removed."
            break
        when 'cleanapps'
            Application.destroyAll (error) ->
                 if error
                     console.log error.stack
                     console.log "Cleaning Applications failed."
                 else
                     console.log "All applications and users are removed."
            break
        when 'cleandb'
            destroyApplications = ->
                Application.destroyAll (error) ->
                     if error
                         console.log error.stack
                         console.log "Cleaning Applications failed."
                     else
                         console.log "All applications and users are removed."

            destroyInstances = ->
                CozyInstance.destroyAll (error) ->
                    if error
                         console.log error.stack
                         console.log "Cleaning instances failed."
                    else
                         destroyApplications()

            destroyUsers = ->
                User.destroyAll (error) ->
                    if error
                         console.log error.stack
                         console.log "Cleaning Users failed."
                    else
                         destroyInstances()

            destroyUsers()
            break

        when 'set_help_url'
            url = process.argv[3]
            CozyInstance.all (err, instances) ->
                if err
                    console.log err
                else if instances.length is 0
                    console.log "No instance found"
                    process.exit 1
                else
                    instance = instances[0]
                    instance.helpUrl = url
                    instance.save (err) ->
                        if err then console.log err
                        else console.log "Help url name set with #{url}"
                        process.exit 0
            break

        when 'setdomain'
            domain = process.argv[3]
            CozyInstance.all (err, instances) ->
                if err
                    console.log err
                    process.exit 1
                else if instances.length is 0
                    CozyInstance.create domain: domain, (err) ->
                        if err then console.log err
                        else console.log "Domain name set with #{domain}"
                        process.exit 0
                else
                    instance = instances[0]
                    instance.domain = domain
                    instance.save (err) ->
                        if err then console.log err
                        else console.log "Domain name set with #{domain}"
                        process.exit 0
            break

        when 'getdomain'
            CozyInstance.all (err, instances) ->
                if err
                    console.log '{domain:"error"}'
                    process.exit 1
                else if instances.length is 0
                    console.log '{domain:null}'
                    process.exit 0
                else
                    console.log "{domain:\"#{instances[0].domain}}\""
                    process.exit 0
            break

runCmd()

{'fraction_non_alphanumeric': 0.0656944072785657, 'fraction_numerical': 0.004549103559004549, 'mean_word_length': 0.948136565024759, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5125547', 'n_tokens_mistral': 1635, 'n_tokens_neox': 1471, 'n_words': 469}