This repository was archived by the owner on Mar 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathcli.js
More file actions
47 lines (40 loc) · 1.26 KB
/
cli.js
File metadata and controls
47 lines (40 loc) · 1.26 KB
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
var config = require('config');
var promptly = require('promptly');
var crypto = require('crypto');
var uuid = require('node-uuid');
var argv = require('yargs')
.usage('Usage: $0 <command> [options]')
.command('create-hash', 'Creates a hash for a password using the defined hash algorithm.')
.command('generate-uuid', 'Generates a UUID which is compatible with Minecraft.')
.demand(1)
.help('h')
.alias('h', 'help')
.argv;
switch (argv._[0]) {
case 'create-hash':
createHash();
break;
case 'generate-uuid':
generateUUID();
break;
default:
console.log('Invalid command! Use --help for more information.');
process.exit(1);
break;
}
function createHash() {
var algorithm = config.get('hashAlgorithm');
var passwordValidator = function (value) {
if (!value) {
throw new Error('Password cannot be empty!');
}
return value;
};
console.log('Hashing algorithm: ', algorithm);
promptly.password('Password: ', { validator: passwordValidator }, function (err, password) {
console.log('Password hash: ', crypto.createHash(algorithm).update(password).digest("hex"));
});
}
function generateUUID() {
console.log(uuid.v4());
}