-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
54 lines (42 loc) · 1.64 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env node
const program = require("commander");
const chalk = require("chalk");
const clipboardy = require("clipboardy");
const createPassword = require("./utils/createPassword");
const savePassword = require("./utils/savePassword");
program.version("1.0.0").description("Simple Password Generator");
// program
// .command("generate")
// .action(() => {
// console.log("Generated");
// })
// .parse();
/*
Adding options (command, description)
program.option("-l, --length", "length of password").parse();
*/
// If we also want the value with the options such as length value
// program.option("-l, --length <number>", "length of password").parse();
// Set a default value to the value of length, let's say = 8
// program.option("-l, --length <number>", "length of password", "8").parse();
// If we want to save the value and more such commands
program
.option("-l, --length <number>", "length of password", "8")
.option("-s, --save", "Save Password to passwords.txt")
.option("-nn, --no-numbers", "Remove numbers")
.option("-ns, --no-symbols", "Remove symbols")
.parse();
// Get the value - print it
// console.log(program.opts());
const { length, save, numbers, symbols } = program.opts();
// Get generated Password
const generatePassword = createPassword(length, numbers, symbols);
// Save to file
if (save) {
savePassword(generatePassword);
}
// Copy to Clipboard
clipboardy.writeSync(generatePassword);
// Output Generated Password
console.log(chalk.blue("Generated Password: ") + chalk.bold(generatePassword));
console.log(chalk.yellow("Password Copied to Clipboard"));