-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
cli.js
executable file
·43 lines (37 loc) · 876 Bytes
/
cli.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
#!/usr/bin/env node
import process from 'node:process';
import meow from 'meow';
import {hashSync, hashingStream} from 'hasha';
const cli = meow(`
Usage
$ hasha <text>
$ cat <file> | hasha
Options
--algorithm, -a Cipher algorithm: md5,sha1,sha256,sha512 [Default: sha512]
--encoding, -e Output encoding: hex,base64,buffer,binary [Default: hex]
Example
$ hasha unicorn --algorithm=md5
1abcb33beeb811dca15f0ac3e47b88d9
`, {
importMeta: import.meta,
flags: {
algorithm: {
type: 'string',
shortFlag: 'a',
},
encoding: {
type: 'string',
shortFlag: 'e',
},
},
});
const input = cli.input[0];
if (!input && process.stdin.isTTY) {
console.log('Specify something to hash');
process.exit(1);
}
if (input) {
console.log(hashSync(input, cli.flags));
} else {
process.stdin.pipe(hashingStream(cli.flags)).pipe(process.stdout);
}