How to use the readline-sync.keyInYNStrict 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 DannyNemer / aang / lib / deprecated / addDescriptions.js View on Github external
function saveTest(tests, newTest, index, promptMsg) {
	if (readlineSync.keyInYNStrict(promptMsg)) {
		// Print success message before "File saved" message.
		util.log('Test added:', util.stylize(newTest.query))

		// Add test to test suite at `index`
		tests[index] = newTest
		util.writeJSONFile(testsFilePath, tests)
	} else {
		util.log('Test not saved.')
	}
}
github PolymathNetwork / polymath-core / CLI / commands / contract_manager.js View on Github external
console.log(`  Owner: ${tickerToModifyDetails[0]}`);
          console.log(`  Registration date: ${tickerToModifyDetails[1]}`);
          console.log(`  Expiry date: ${tickerToModifyDetails[2]}`);
          console.log(`  Token name: ${tickerToModifyDetails[3]}`);
          console.log(`  Status: ${tickerToModifyDetails[4] ? 'Deployed' : 'Not deployed'}\n`);
        }
        let tickerOwner = readlineSync.question(`Enter the token owner: `, {
          limit: function(input) {
            return web3.utils.isAddress(input);
          },
          limitMessage: "Must be a valid address"
        });
        let tickerSTName = readlineSync.question(`Enter the token name: `);
        let tickerRegistrationDate = readlineSync.question(`Enter the Unix Epoch time on which ticker get registered: `);
        let tickerExpiryDate = readlineSync.question(`Enter the Unix Epoch time on wich the ticker will expire: `);
        let tickerStatus = readlineSync.keyInYNStrict(`Is the token deployed?`);
        let modifyTickerAction = currentContract.methods.modifyTicker(tickerOwner, tickerToModify, tickerSTName, tickerRegistrationDate, tickerExpiryDate, tickerStatus);
        await common.sendTransaction(modifyTickerAction, {factor: 1.5});
        console.log(chalk.green(`Ticker has been updated successfully`));
        break;
      case 'Remove Ticker':
        let tickerToRemove = readlineSync.question('Enter the token symbol that you want to remove: ');
        let tickerToRemoveDetails = await currentContract.methods.getTickerDetails(tickerToRemove).call();
        if (tickerToRemoveDetails[1] == 0) {
          console.log(chalk.yellow(`${ticker} does not exist.`));
        } else {
          let removeTickerAction = currentContract.methods.removeTicker(tickerToRemove);
          await common.sendTransaction(removeTickerAction, {factor: 3});
          console.log(chalk.green(`Ticker has been removed successfully`));
        }
        break;
      case 'Modify SecurityToken':
github scottmcpherson / meteor-io / lib / utilities / file-system.js View on Github external
confirmFileOverwriteIfExists(file) {
    if (this.isFile(file)) {
      this.logError(`File already exists: ${file}`);
      if (!readlineSync.keyInYNStrict('Do you want to overwrite it?')) {
        process.exit();
      }
    }
  }
github PolymathNetwork / polymath-core / CLI / commands / wallet_manager.js View on Github external
async function addSchedule(beneficiary, allTemplateNames) {
  const minuteFromNow = Math.floor(Date.now() / 1000) + 60;
  const startTime = input.readDateInTheFuture(`Enter the start date (Unix Epoch time) of the vesting schedule (a minute from now = ${minuteFromNow}): `, minuteFromNow);
  
  const currentBalance = await securityToken.methods.balanceOf(Issuer.address).call();
  console.log(chalk.yellow(`Your current balance is ${web3.utils.fromWei(currentBalance)} ${tokenSymbol}`));
  
  const useTemplate = readlineSync.keyInYNStrict(`Do you want to use an existing template?`);
  let action;
  let templateData;
  if (useTemplate) {
    const allTemplates = await getTemplates(allTemplateNames);
    templateData = selectTemplate(allTemplates);
    action = currentWalletModule.methods.addScheduleFromTemplate(beneficiary, web3.utils.toHex(templateData.name), startTime);
  } else {
    templateData = inputTemplateData();
    action = currentWalletModule.methods.addSchedule(
      beneficiary,
      web3.utils.toHex(templateData.name),
      web3.utils.toWei(templateData.amount),
      templateData.duration,
      templateData.frequency,
      startTime
    );
github PolymathNetwork / polymath-core / CLI / commands / voting_manager.js View on Github external
async function addVotingModule() {
  const moduleList = (await common.getAvailableModules(moduleRegistry, gbl.constants.MODULES_TYPES.DIVIDENDS, securityToken.options.address)).filter(m => m.name.includes('Voting'));
  const options = moduleList.map(m => `${m.name} - ${m.version} (${m.factoryAddress})`);

  const index = readlineSync.keyInSelect(options, 'Which voting module do you want to add? ', { cancel: 'RETURN' });
  if (index !== -1 && readlineSync.keyInYNStrict(`Are you sure you want to add ${options[index]}? `)) {
    const moduleABI = abis.advancedPLCRVotingCheckpointABI();
    await common.addModule(securityToken, polyToken, moduleList[index].factoryAddress, moduleABI);
  }
}
github PolymathNetwork / polymath-core / CLI / commands / permission_manager.js View on Github external
async function addPermissionModule() {
  let moduleList = await common.getAvailableModules(moduleRegistry, gbl.constants.MODULES_TYPES.PERMISSION, securityToken.options.address);
  let options = moduleList.map(m => `${m.name} - ${m.version} (${m.factoryAddress})`);

  let index = readlineSync.keyInSelect(options, 'Which permission manager module do you want to add? ', { cancel: 'Return' });
  if (index != -1 && readlineSync.keyInYNStrict(`Are you sure you want to add ${options[index]}? `)) {
    const moduleABI = abis.generalPermissionManager();
    await common.addModule(securityToken, polyToken, moduleList[index].factoryAddress, moduleABI);
  }
}
github PolymathNetwork / polymath-core / CLI / commands / transfer_manager.js View on Github external
async function addTransferManagerModule() {
  let availableModules = await moduleRegistry.methods.getModulesByTypeAndToken(gbl.constants.MODULES_TYPES.TRANSFER, securityToken.options.address).call();
  let options = await Promise.all(availableModules.map(async function (m) {
    let moduleFactoryABI = abis.moduleFactory();
    let moduleFactory = new web3.eth.Contract(moduleFactoryABI, m);
    return web3.utils.hexToUtf8(await moduleFactory.methods.name().call());
  }));

  let index = readlineSync.keyInSelect(options, 'Which Transfer Manager module do you want to add? ', { cancel: 'RETURN' });
  if (index != -1 && readlineSync.keyInYNStrict(`Are you sure you want to add ${options[index]} module?`)) {
    let bytes = web3.utils.fromAscii('', 16);
    switch (options[index]) {
      case 'CountTransferManager':
        let maxHolderCount = readlineSync.question('Enter the maximum no. of holders the SecurityToken is allowed to have: ');
        let configureCountTM = abis.countTransferManager().find(o => o.name === 'configure' && o.type === 'function');
        bytes = web3.eth.abi.encodeFunctionCall(configureCountTM, [maxHolderCount]);
        break;
      case 'PercentageTransferManager':
        let maxHolderPercentage = toWeiPercentage(readlineSync.question('Enter the maximum amount of tokens in percentage that an investor can hold: ', {
          limit: function (input) {
            return (parseInt(input) > 0 && parseInt(input) <= 100);
          },
          limitMessage: "Must be greater than 0 and less than 100"
        }));
        let allowPercentagePrimaryIssuance = readlineSync.keyInYNStrict(`Do you want to ignore transactions which are part of the primary issuance? `);
        let configurePercentageTM = abis.percentageTransferManager().find(o => o.name === 'configure' && o.type === 'function');
github asamuzaK / withExEditorHost / modules / setup.js View on Github external
throw new Error(`No such directory: ${configPath}.`);
  }
  const editorArgs = setupOpts.get("editorArgs");
  const editorPath = setupOpts.get("editorPath");
  const overwriteEditorConfig = setupOpts.get("overwriteEditorConfig");
  const file = path.join(configPath, EDITOR_CONFIG_FILE);
  let func;
  setupOpts.set("configPath", configPath);
  if (isString(editorPath)) {
    setupOpts.set("editorFilePath", editorPath.trim());
  }
  if (isString(editorArgs)) {
    setupOpts.set("editorCmdArgs", new CmdArgs(editorArgs.trim()).toArray());
  }
  if (isFile(file) && !overwriteEditorConfig) {
    const ans = readline.keyInYNStrict(`${file} already exists.\nOverwrite?`);
    if (ans) {
      func = createEditorConfig().catch(throwErr);
    } else {
      func = abortSetup(`${file} already exists.`);
    }
  } else {
    func = createEditorConfig().catch(throwErr);
  }
  return func || null;
};