25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

75 lines
2.2 KiB

  1. #!/usr/bin/env node
  2. 'use strict';
  3. var cpypst = require('copy-paste');
  4. var meow = require('meow');
  5. var LessPass = require('lesspass');
  6. var read = require('read');
  7. var cli = meow(`
  8. Usage
  9. $ lesspass <site> <login> <masterPassword>
  10. Options
  11. --lowercase, -l true or false (default true)
  12. --uppercase, -u true or false (default true)
  13. --symbols, -s true or false (default true)
  14. --numbers, -n true or false (default true)
  15. --clipboard, -C true or false (default false)
  16. --length, -L int (default 12)
  17. --counter, -c int (default 1)
  18. Examples
  19. $ lesspass lesspass.com contact@lesspass.com 'my Master Password' --length=14 -s=false
  20. onAV7eqIM1arOZ
  21. `, {
  22. alias: {
  23. l: 'lowercase',
  24. u: 'uppercase',
  25. s: 'symbols',
  26. n: 'numbers',
  27. L: 'length',
  28. c: 'counter',
  29. C: 'clipboard',
  30. }
  31. });
  32. function calcPassword(site, login, masterPassword, options) {
  33. LessPass.generatePassword(site, login, masterPassword, options).then(generatedPassword => {
  34. if (options.clipboard == true) {
  35. cpypst.copy(generatedPassword);
  36. console.log("Copied to clipboard");
  37. process.exit();
  38. } else {
  39. console.log(generatedPassword);
  40. process.exit();
  41. }
  42. });
  43. }
  44. var lowercase = (cli.flags.lowercase || 'true').toLowerCase() === 'true';
  45. var uppercase = (cli.flags.uppercase || 'true').toLowerCase() === 'true';
  46. var symbols = (cli.flags.symbols || 'true').toLowerCase() === 'true';
  47. var numbers = (cli.flags.numbers || 'true').toLowerCase() === 'true';
  48. var clipboard = (cli.flags.clipboard || 'false').toLowerCase() === 'true';
  49. var options = {
  50. counter: cli.flags.counter || 1,
  51. length: cli.flags.length || 16,
  52. lowercase: lowercase,
  53. uppercase: uppercase,
  54. numbers: numbers,
  55. symbols: symbols,
  56. clipboard: clipboard
  57. };
  58. var site = cli.input[0];
  59. var login = cli.input[1];
  60. if (cli.input.length === 3) {
  61. var masterPassword = cli.input[2];
  62. calcPassword(site, login, masterPassword, options)
  63. } else {
  64. read({prompt: 'master password: ', silent: true}, function (er, password) {
  65. calcPassword(site, login, password, options)
  66. });
  67. }