-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmy_ciphering_cli.js
39 lines (35 loc) · 1.14 KB
/
my_ciphering_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
const process = require('process');
const { pipeline } = require('stream');
const { getInputStream } = require('./readable/input-stream');
const { getOutputStream } = require('./writable/output-stream');
const { parseArgs } = require('./args-handler');
const getTransformCiphers = require('./transforms/transform-builder');
const ValidationError = require('./errors/validation-error');
const FileAccessError = require('./errors/file-access-error');
try {
const rawArgs = process.argv.slice(2);
const args = parseArgs(rawArgs);
const inputStream = getInputStream(args);
const transformStreams = getTransformCiphers(args);
const outputStream = getOutputStream(args);
pipeline(
inputStream,
...transformStreams,
outputStream,
(err) => {
if (err) {
process.stderr.write(err.message);
process.exit(1);
}
}
);
} catch (err) {
if (err instanceof ValidationError) {
process.stderr.write(`Validation error: ${err.message}\n`);
} else if (err instanceof FileAccessError) {
process.stderr.write(`File error: ${err.message}\n`);
} else {
process.stderr.write(err.message);
}
process.exit(1);
}