How to use the readline-sync.question function in readline-sync

To help you get started, we’ve selected a few readline-sync examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github kuzzleio / kuzzle / bin / commands / resetSecurity.js View on Github external
function commandResetSecurity (options) {
  const
    cout = new ColorOutput(options);

  let userIsSure = false;

  console.log(cout.warn('[ℹ] You are about to clear all created users, profiles and roles.'));
  console.log(cout.warn('[ℹ] This operation cannot be undone.\n'));

  if (!params.noint) {
    userIsSure = readlineSync.question('[❓] Are you sure? If so, please type "I am sure": ') === 'I am sure';
  }
  else {
    // non-interactive mode
    userIsSure = true;
  }

  if (userIsSure) {
    console.log(cout.notice('[ℹ] Processing...\n'));
    const query = {
      controller: 'admin',
      action: 'resetSecurity'
    };

    return sendAction(query, options)
      .then(() => {
        console.log(cout.ok('[✔] Kuzzle users, profiles and roles have been successfully reset'));
github schemaio / schema-node-client / cli / commands.js View on Github external
if (fs.existsSync(infoPath)) {
    info = JSON.parse(fs.readFileSync(infoPath)) || {};
  } else {
    console.log('Creating ' + infoPath + ' -- please add it to .gitignore if applicable');
  }

  if (info.root !== root) {
    writeInfo(info, { root: root });
  }

  if (info.dir !== dirPath) {
    writeInfo(info, { dir: dirPath });
  }

  if (!info.clientId || resetAuth) {
    var clientId = readlineSync.question(
      'Enter your client ID: '
    );
    writeInfo(info, { clientId: clientId });
  }

  if (!info.secretKey || resetAuth) {
    var secretKey = readlineSync.question(
      'Enter your client secret key: ', {
        hideEchoBack: true
      }
    );
    // Encrypt key just in case it gets committed or shared
    writeInfo(info, { secretKey: encryptSecret(secretKey) });
  }

  resetAuth = false;
github Azure-Samples / cognitive-services-personalizer-samples / quickstarts / node / sample.js View on Github external
function continueLoop() {
  var answer = readline.question("\nPress q to break, any other key to continue.\n")
  if (answer.toLowerCase() === 'q') {
    return false;
  }
  return true;
}
// 
github fluidtrends / awsome / lib / old / config.js View on Github external
initInteractive: function () {
    var key    = readline.question('Enter your AWS key:');
    var secret = readline.question('Enter your AWS secret:');
    var region = readline.question('Enter your AWS region:');

    return config.init(key, secret, region);
  },
github aieater / gpueater_nodejs / index.js View on Github external
function load_config() {
	try { eater_config = JSON.parse(fs.readFileSync(`.eater`).toString()); } catch (e) {
		try { eater_config = JSON.parse(fs.readFileSync(path.join(HOME,".eater")).toString()); } catch (e) {
			console.error(`You must prepare ${path.join(HOME,".eater")} or .eater file.`);
			console.info(`Setup GPUEater config to ${path.join(HOME,".eater")} file.`);
			if (global_params.interactive) {
				const readlineSync = require('readline-sync');
				let email = readlineSync.question('email: ');
				let pass = readlineSync.question('password: ', {hideEchoBack: true});
				let obj = {gpueater:{email:email,password:pass}};
				fs.writeFileSync(path.join(HOME,".eater"),JSON.stringify(obj));
				console.info(`GPUEater config saved to ${path.join(HOME,".eater")}.`);
				eater_config = obj;
			} else {
				throw "Could not load a config file.";
			}
		}
	}
	let stored_hash = "A";
	let hash = "B";
	try {stored_hash = fs.readFileSync(CONFIG_HASH_PATH);} catch (e) {}
	hash = crypto.createHmac('sha256', 'dummy').update(JSON.stringify(eater_config)).digest('hex');

	if (stored_hash == hash) {
		try { global_header['Cookie'] = fs.readFileSync(COOKIE_PATH);} catch (e) { }
github BrowenChen / EducationAlgorithms / cat.js View on Github external
var getUserPrompt = function(question){
	var answer = readlineSync.question(question + '\n' );
	console.log("Your answer is: \n");
	return answer;
}
github PolymathNetwork / polymath-core / CLI / commands / transfer_manager.js View on Github external
async function removeRestrictionsInBatch() {
  let csvFilePath = readlineSync.question(`Enter the path for csv data file (${REMOVE_RESTRICTIONS_DATA_CSV}): `, {
    defaultInput: REMOVE_RESTRICTIONS_DATA_CSV
  });
  let batchSize = readlineSync.question(`Enter the max number of records per transaction or batch size (${gbl.constants.DEFAULT_BATCH_SIZE}): `, {
    limit: function (input) {
      return parseInt(input) > 0;
    },
    limitMessage: 'Must be greater than 0',
    defaultInput: gbl.constants.DEFAULT_BATCH_SIZE
  });
  let parsedData = csvParse(csvFilePath);
  let validData = parsedData.filter(row => web3.utils.isAddress(row[0]));
  let invalidRows = parsedData.filter(row => !validData.includes(row));
  if (invalidRows.length > 0) {
    console.log(chalk.red(`The following lines from csv file are not valid: ${invalidRows.map(r => parsedData.indexOf(r) + 1).join(',')} `));
  }
  let batches = common.splitIntoBatches(validData, batchSize);
  let [holderArray] = common.transposeBatches(batches);
  for (let batch = 0; batch < batches.length; batch++) {
    console.log(`Batch ${batch + 1} - Attempting to remove restrictions to the following accounts: \n\n`, holderArray[batch], '\n');
github PolymathNetwork / polymath-core / CLI / commands / transfer_manager.js View on Github external
limitMessage: "Must be a valid address"
  });
  let to = readlineSync.question('Enter the address to which transfers will be approved: ', {
    limit: function (input) {
      return web3.utils.isAddress(input);
    },
    limitMessage: "Must be a valid address"
  });
  if (!await getManualApproval(from, to)) {
    let description = readlineSync.question('Enter the description for the manual approval: ', {
      limit: function (input) {
        return input != "" && getBinarySize(input) < 33
      },
      limitMessage: "Description is required"
    });
    let allowance = readlineSync.question('Enter the amount of tokens which will be approved: ');
    let oneHourFromNow = Math.floor(Date.now() / 1000 + 3600);
    let expiryTime = readlineSync.questionInt(`Enter the time (Unix Epoch time) until which the transfer is allowed (1 hour from now = ${oneHourFromNow}): `, { defaultInput: oneHourFromNow });
    let addManualApprovalAction = currentTransferManager.methods.addManualApproval(from, to, web3.utils.toWei(allowance), expiryTime, web3.utils.fromAscii(description));
    let addManualApprovalReceipt = await common.sendTransaction(addManualApprovalAction);
    let addManualApprovalEvent = common.getEventFromLogs(currentTransferManager._jsonInterface, addManualApprovalReceipt.logs, 'AddManualApproval');
    console.log(chalk.green(`Manual approval has been added successfully!`));
  } else {
    console.log(chalk.red(`A manual approval already exists from ${from} to ${to}. Revoke it first if you want to add a new one or modify the existing one.`));
  }
}
github mongaku / mongaku / src / utils / create-source.js View on Github external
module.exports = (args, callback) => {
    const types = Object.keys(options.types);

    const _id = rl.question("Source ID (e.g. frick): ");
    const name = rl.question("Full Name (e.g. Frick Library): ");
    const shortName = rl.question("Short Name (e.g. Frick): ");
    const url = rl.question("URL (http://...): ");
    const isPrivate = rl.keyInYN("Private?: ");
    const type = rl.question(`Data Type (${types.join(", ")}): `);
    const converter = rl.question("Data Convertor [default]: ", {
        defaultInput: "default",
    });

    const Source = models("Source");
    const source = new Source({
        _id,
        name,
        shortName,
        url,
        private: isPrivate,
        type,
        converter,
    });
github PolymathNetwork / polymath-core / CLI / commands / transfer_manager.js View on Github external
async function modifyRestrictionsInBatch() {
  let csvFilePath = readlineSync.question(`Enter the path for csv data file (${MODIFY_RESTRICTIONS_DATA_CSV}): `, {
    defaultInput: MODIFY_RESTRICTIONS_DATA_CSV
  });
  let batchSize = readlineSync.question(`Enter the max number of records per transaction or batch size (${gbl.constants.DEFAULT_BATCH_SIZE}): `, {
    limit: function (input) {
      return parseInt(input) > 0;
    },
    limitMessage: 'Must be greater than 0',
    defaultInput: gbl.constants.DEFAULT_BATCH_SIZE
  });
  let parsedData = csvParse(csvFilePath);
  let validData = parsedData.filter(
    row => web3.utils.isAddress(row[0]) &&
      !isNaN(row[1]) &&
      moment.unix(row[2]).isValid() &&
      (!isNaN(row[3]) && (parseFloat(row[3]) % 1 === 0)) &&
      moment.unix(row[4]).isValid() &&
      typeof row[5] === 'string' && RESTRICTION_TYPES.includes(row[5]));
  let invalidRows = parsedData.filter(row => !validData.includes(row));
  if (invalidRows.length > 0) {