examples/cli.js
function getCommandLineOptions() {
  return process.argv
    .slice(2)
    .map(arg => arg.split('='))
    .reduce((accum, arg) => {
      const key = arg[0].replace('--', '');

      // if secret, do not put in config
      if (key === 'secret') {
        secret = arg[1];
        return accum;
      }

      // If provided key is not encoded, encode it first
      // do not put in config
      if (key === 'privatekey') {
        secret = otplib.authenticator.encode(arg[1]);
        return accum;
      }

      if (key === 'step' || key === 'epoch') {
        accum[key] = parseInt(arg[1], 10);
        return accum;
      }

      return accum;
    }, {});
}
function getCommandLineOptions() {
  return process.argv
    .slice(2)
    .map(arg => arg.split('='))
    .reduce((accum, arg) => {
      const key = arg[0].replace('--', '');

      // if secret, do not put in config
      if (key === 'secret') {
        secret = arg[1];
        return accum;
      }

      // If provided key is not encoded, encode it first
      // do not put in config
      if (key === 'privatekey') {
        secret = otplib.authenticator.encode(arg[1]);
        return accum;
      }

      if (key === 'step' || key === 'epoch') {
        accum[key] = parseInt(arg[1], 10);
        return accum;
      }

      return accum;
    }, {});
}
function getCommandLineOptions ( ) { return process . argv . slice ( 2 ) . map ( arg => arg . split ( '=' ) ) . reduce ( ( accum , arg ) => { const key = arg [ 0 ] . replace ( '--' , '' ) ; // if secret, do not put in config if ( key === 'secret' ) { secret = arg [ 1 ] ; return accum ; } // If provided key is not encoded, encode it first // do not put in config if ( key === 'privatekey' ) { secret = otplib . authenticator . encode ( arg [ 1 ] ) ; return accum ; } if ( key === 'step' || key === 'epoch' ) { accum [ key ] = parseInt ( arg [ 1 ] , 10 ) ; return accum ; } return accum ; } , { } ) ; }
Parse and prepare CLI values
Parse and prepare CLI values