<commit_before>/*
 * cushion-cli
 * https://github.com/stefanjudis/cushion-cli
 *
 * Copyright (c) 2012 <NAME>
 * Licensed under the MIT license.
 */

var cPrompt = module.exports = {},
    prompt = require('prompt'),
    //messages = require('./messages');
    schema = {
      properties: {
        command: {
          pattern: /^[a-zA-Z0-9\s\-\_\=\&\'\"\/]+$/,
          message: 'Name must be only letters, numbers, spaces or dashes',
          required: true
        }
      }
    };


/**
 * display prompt and
 * gets connection information to establish it
 *
 * @param  {Function} callback callback called after user input
 */
cPrompt.setup = function(callback) {
  prompt.message = 'Cushion'.blue;

  prompt.get(
    {
      properties: {
        admin: {
          message: 'First of all. Do you want to login as admin?',
          validator: /y[es]*|n[o]?/,
          warning: 'Must respond y[es] or n[o]',
          default: 'no'
        },
        host: {
          message: 'What is the host?',
          default: '127.0.0.1'
        },
        port: {
          message: 'What is the port?',
          default: '5984'
        }
      }
    }, function(error, result) {
      if (!error) {
        if (result.admin.match(/y[es]*/)) {
          cPrompt._setupAdmin(result, callback);

        } else {
          callback(result);
        }
      } else {
        cPrompt._showError();
      }
    }
  );
};


/**
 * display prompt and
 * get connection information like admin name and admin password
 * and call callback afterwards
 *
 * @param   {object}   result   object with inputted connection information
 * @param   {Function} callback callback called after user input
 * @private
 */
cPrompt._setupAdmin = function(result, callback) {
  prompt.get(
    {
      properties: {
        name: {
          message: 'What is the admin name?'
        },
        password: {
          message: 'What is the password',
          hidden: true
        }
      }
    },
    function(error, adminData) {
      if (!error) {
        result.name = adminData.name;
        result.password = <PASSWORD>;

        callback(result);
      } else {
        cPrompt._showError();
      }
    }
  );
};


/**
 * display prompt and
 * get information like admin name and admin passwort
 * and create admin afterwards
 *
 * @param   {object} cli general cli object
 * @private
 */
cPrompt._createAdmin = function(cli) {
  prompt.get(
    {
      properties: {
        name: {
          message: 'What is the admin name?'
        },
        password: {
          message: 'What is the password',
          hidden: true
        }
      }
    },
    function(error, result) {
      if (!error) {
        cli.cushion.createAdmin(
          result.name,
          result.password,
          cli.connectionCallbacks.createAdmin
        );
      } else {
        cPrompt._showError();
      }
    }
  );
};


/**
 * display prompt and get name of
 * admin who should be deleted
 *
 * @param   {object} cli general cli object
 * @private
 */
cPrompt._deleteAdmin = function(cli) {
  prompt.get(
    {
      properties: {
        name: {
          'message': 'What is the admin name?'
        }
      }
    },
    function(error, result) {
      if (!error) {
        cli.cushion.deleteAdmin(
          result.name,
          cli.connectionCallbacks.deleteAdmin
        );
      } else {
        cPrompt._showError();
      }
    }
  );
};


/**
 * display errors a nicer way and
 * start setup again
 *
 * @private
 */
cPrompt._showError = function() {
  console.log(
    'There was a problem with the prompt.\n' +
    'Let\'s start all over again...'
  );

  cPrompt.setup();
};


/**
 * Main function for connection loop
 * Get command and execute it at connectionCommands.js
 *
 * @param  {object} cli general cli object
 */
cPrompt.connection = function(cli) {
  prompt.delimiter = ' <> '.red;
  prompt.message = 'Connection'.blue;
  prompt.start();
<commit_msg>rename showError to handleError -> better function declaration<commit_after>/*
 * cushion-cli
 * https://github.com/stefanjudis/cushion-cli
 *
 * Copyright (c) 2012 <NAME>
 * Licensed under the MIT license.
 */

var cPrompt = module.exports = {},
    prompt = require('prompt'),
    //messages = require('./messages');
    schema = {
      properties: {
        command: {
          pattern: /^[a-zA-Z0-9\s\-\_\=\&\'\"\/]+$/,
          message: 'Name must be only letters, numbers, spaces or dashes',
          required: true
        }
      }
    };


/**
 * display prompt and
 * gets connection information to establish it
 *
 * @param  {Function} callback callback called after user input
 */
cPrompt.setup = function(callback) {
  prompt.message = 'Cushion'.blue;

  prompt.get(
    {
      properties: {
        admin: {
          message: 'First of all. Do you want to login as admin?',
          validator: /y[es]*|n[o]?/,
          warning: 'Must respond y[es] or n[o]',
          default: 'no'
        },
        host: {
          message: 'What is the host?',
          default: '127.0.0.1'
        },
        port: {
          message: 'What is the port?',
          default: '5984'
        }
      }
    }, function(error, result) {
      if (!error) {
        if (result.admin.match(/y[es]*/)) {
          cPrompt._setupAdmin(result, callback);

        } else {
          callback(result);
        }
      } else {
        cPrompt._handleError();
      }
    }
  );
};


/**
 * display prompt and
 * get connection information like admin name and admin password
 * and call callback afterwards
 *
 * @param   {object}   result   object with inputted connection information
 * @param   {Function} callback callback called after user input
 * @private
 */
cPrompt._setupAdmin = function(result, callback) {
  prompt.get(
    {
      properties: {
        name: {
          message: 'What is the admin name?'
        },
        password: {
          message: '<PASSWORD> is the password',
          hidden: true
        }
      }
    },
    function(error, adminData) {
      if (!error) {
        result.name = adminData.name;
        result.password = <PASSWORD>;

        callback(result);
      } else {
        cPrompt._handleError();
      }
    }
  );
};


/**
 * display prompt and
 * get information like admin name and admin passwort
 * and create admin afterwards
 *
 * @param   {object} cli general cli object
 * @private
 */
cPrompt._createAdmin = function(cli) {
  prompt.get(
    {
      properties: {
        name: {
          message: 'What is the admin name?'
        },
        password: {
          message: '<PASSWORD>',
          hidden: true
        }
      }
    },
    function(error, result) {
      if (!error) {
        cli.cushion.createAdmin(
          result.name,
          result.password,
          cli.connectionCallbacks.createAdmin
        );
      } else {
        cPrompt._handleError();
      }
    }
  );
};


/**
 * display prompt and get name of
 * admin who should be deleted
 *
 * @param   {object} cli general cli object
 * @private
 */
cPrompt._deleteAdmin = function(cli) {
  prompt.get(
    {
      properties: {
        name: {
          'message': 'What is the admin name?'
        }
      }
    },
    function(error, result) {
      if (!error) {
        cli.cushion.deleteAdmin(
          result.name,
          cli.connectionCallbacks.deleteAdmin
        );
      } else {
        cPrompt._handleError();
      }
    }
  );
};


/**
 * display errors a nicer way and
 * start setup again
 *
 * @private
 */
cPrompt._handleError = function() {
  console.log(
    'There was a problem with the prompt.\n' +
    'Let\'s start all over again...'
  );

  cPrompt.setup();
};


/**
 * Main function for connection loop
 * Get command and execute it at connectionCommands.js
 *
 * @param  {object} cli general cli object
 */
cPrompt.connection = function(cli) {
  prompt.delimiter = ' <> '.red;
  prompt.message = 'Connection'.blue;
  prompt.start();

{'fraction_non_alphanumeric': 0.13028743567214762, 'fraction_numerical': 0.004016568344420736, 'mean_word_length': 1.8661870503597122, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 12, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '2600914', 'n_tokens_mistral': 2426, 'n_tokens_neox': 2373, 'n_words': 629}