def main():
    '''
        Main part of command line utility
    '''
    arguments = docopt.docopt(__doc__, version='Naval Fate 2.0')

    if arguments['show_diag']:
        diag.show()

    if arguments['show_reporting']:
        diag.reporting()
        diag.show()

    if arguments['ping_couchdb']:
        try:
            if couchdb.ping():
                print 'OK'
            else:
                print 'KO'
        except:
            print 'KO'

    if arguments['get_admin']:
        (username, password) = couchdb.get_admin()
        print 'Username: {}'.format(username)
        print 'Password: {}'.format(password)

    if arguments['get_couchdb_admins']:
        admins = couchdb.get_couchdb_admins()
        print 'CouchDB admins:'
        for admin in admins:
            print '- {}'.format(admin)

    if arguments['delete_token']:
        couchdb.delete_token()

    if arguments['create_token']:
        print couchdb.create_token()

    if arguments['create_cozy_db']:
        if arguments['--name']:
            db_name = arguments.get('<name>', 'cozy')
        else:
            db_name = 'cozy'
        couchdb.create_cozy_db(db_name)
        print '{} DB is ready'.format(db_name)

    if arguments['reset_token']:
        couchdb.reset_token()
        print 'New tokens:'
        print couchdb.get_admin()[0]

    if arguments['get_cozy_param']:
        print couchdb.get_cozy_param(arguments['<name>'])

    if arguments['normalize_cert_dir']:
        ssl.normalize_cert_dir()

    if arguments['get_crt_common_name']:
        filename = arguments['<filename>']
        if filename:
            print ssl.get_crt_common_name(filename)
        else:
            print ssl.get_crt_common_name()

    if arguments['clean_links']:
        ssl.clean_links()

    if arguments['make_links']:
        ssl.make_links(arguments['<common_name>'])

    if arguments['generate_certificate']:
        common_name = arguments['<common_name>']

        if arguments['--size']:
            key_size = int(arguments['<size>'])
        else:
            key_size = ssl.DEFAULT_KEY_SIZE

        print 'Generate certificate for {} with {} key size'.format(common_name, key_size)
        ssl.generate_certificate(common_name, key_size)

    if arguments['sign_certificate']:
        common_name = arguments['<common_name>']

        print "Sign certificate for {} with Let's Encrypt".format(common_name)
        ssl.acme_sign_certificate(common_name)

    if arguments['renew_certificates']:
        ssl.acme_renew_certificates()

    if arguments['compare_version']:
        current = arguments['<current>']
        operator = arguments['<operator>']
        reference = arguments['<reference>']
        compare_version.compare(current, operator, reference)

    if arguments['is_cozy_registered']:
        print couchdb.is_cozy_registered()

    if arguments['unregister_cozy']:
        couchdb.unregister_cozy()

    if arguments['fix_oom_scores']:
        process.fix_oom_scores()

    if arguments['get_oom_scores']:
        process.get_oom_scores()

    if arguments['rebuild_app']:
        if arguments['--not-force']:
            force = False
        else:
            force = True
        if arguments['--restart']:
            restart = True
        else:
            restart = False
        migration.rebuild_app(arguments['<app>'], force=force, restart=restart)

    if arguments['rebuild_all_apps']:
        if arguments['--not-force']:
            force = False
        else:
            force = True
        if arguments['--restart']:
            restart = True
        else:
            restart = False
        migration.rebuild_all_apps(force=force, restart=restart)

    if arguments['migrate_2_node4']:
        migration.migrate_2_node4()

    if arguments['install_requirements']:
        migration.install_requirements()

    if arguments['install_cozy']:
        migration.install_cozy()

    if arguments['wait_couchdb']:
        helpers.wait_couchdb()

    if arguments['wait_cozy_stack']:
        helpers.wait_cozy_stack()

    if arguments['check_lsb_codename']:
        sys.exit(diag.check_lsb_codename())

    if arguments['emulate_smtp']:
        ip = '127.0.0.1'
        port = '25'
        if arguments['--bind']:
            ip = arguments['<ip>']
        if arguments['--port']:
            if arguments['<port>']:  # a bug in docopt?
                port = arguments['<port>']
            else:
                port = arguments['<ip>']

        print 'Emulate SMTP server on {}:{}'.format(ip, port)
        smtpd.DebuggingServer(tuple([ip, int(port)]), None)
        asyncore.loop()

    if arguments['backup']:
        if arguments['<backup_filename>']:
            backup_filename = arguments['<backup_filename>']
        else:
            backup_filename = None
        backup.backup(backup_filename)

    if arguments['restore']:
        backup.restore(arguments['<backup_filename>'])

    if arguments['install_weboob'] or arguments['update_weboob']:
        weboob.install()

    if arguments['update_weboob_modules']:
        weboob.update()
Main part of command line utility