-
Notifications
You must be signed in to change notification settings - Fork 12
/
cli.ts
74 lines (67 loc) · 2.3 KB
/
cli.ts
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env node
import { mosaic } from './index';
import * as commander from 'commander';
let checkArguments = (
inputImage: string,
tilesDirectory: string,
thumbsReadDirectory: string,
thumbsWriteDirectory: string,
cellWidth: number,
cellHeight: number,
rows: number,
columns: number
) => {
if( !inputImage ) {
console.log('Error: option -i, --input-image <image_path> missing');
process.exit();
}
if( !tilesDirectory && !thumbsReadDirectory ) {
console.log('Error: you need to specify either -d, --tiles-directory or -tr, --thumbs-read');
process.exit();
}
};
/**
* Get parameters if we are executing the script directly from CLI
*/
commander
.version('1.1.5')
.option('-i, --input-image [input_image]', 'The input image path')
.option('-d, --tiles-directory [tiles_directory]', 'The tiles directory path')
.option('-R, --thumbs-read [thumbs_read_directory]', 'The thumbnails read directory')
.option('-W, --thumbs-write [thumbs_write_directory]', 'The thumbnails write directory')
.option('-r, --rows [rows]', 'The number of rows of the output image')
.option('-c, --columns [columns]', 'The number of columns of the output image')
.option('-w, --cell-width [width]', 'The cell width of each cell of the output image')
.option('-h, --cell-height [height]', 'The cell height of each cell of the output image')
.option('-l, --disable-log [true/false]', 'Disable console logging')
.parse(process.argv);
let inputImage: string = commander.inputImage;
let tilesDirectory: string = commander.tilesDirectory;
let thumbsReadDirectory: string = commander.thumbsRead;
let thumbsWriteDirectory: string = commander.thumbsWrite;
let cellWidth: number = Number.parseInt(commander.cellWidth);
let cellHeight: number = Number.parseInt(commander.cellHeight);
let columns: number = Number.parseInt(commander.columns);
let rows: number = Number.parseInt(commander.rows);
let enableLog: boolean = commander.disableLog ? false : true;
checkArguments(
inputImage,
tilesDirectory,
thumbsReadDirectory,
thumbsWriteDirectory,
cellWidth,
cellHeight,
columns,
rows
);
mosaic(
inputImage,
tilesDirectory,
cellWidth,
cellHeight,
columns,
rows,
thumbsReadDirectory,
thumbsWriteDirectory,
enableLog
);