-
Notifications
You must be signed in to change notification settings - Fork 17
/
cli.js
executable file
·62 lines (54 loc) · 1.61 KB
/
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env node
'use strict';
var m_opts = {
boolean: ['color', 'help'],
alias: {
'color': 'c',
'c-ratio': 'r',
'fit': 'f',
'height': 't',
'width': 'w',
'help': '?'
}
}
var argv = require('minimist')(process.argv.slice(2), m_opts);
// Output help and quit
if (argv.help || argv.h) {
console.log('');
console.log(' Usage: asciify [options] [path]');
console.log('');
console.log(' Options:');
console.log('');
console.log(' -c, --color true for color, false for B/W');
console.log(' -r, --c-ratio character width-height ratio');
console.log(' -f, --fit resize rule: box, height, width, original, none');
console.log(' -t, --height height to resize to');
console.log(' -w, --width width to resize to');
console.log('');
console.log(' See the readme for detailed options and defaults');
console.log('');
console.log(' Example:');
console.log('');
console.log(' $ asciify lolwut.png -c false');
console.log('');
process.exit(0);
}
// Create options for arguments
var options = {
color: argv['color'],
c_ratio: argv['c-ratio'],
fit: argv['fit'],
height: argv['height'],
width: argv['width']
}
var errorOutput = function(message) {
console.log(message);
process.exit(1);
}
// Setup defaults just for CLI
if (!options.fit) options.fit = 'box';
if (!options.width) options.width = '100%';
if (!options.height) options.height = '100%';
if (!argv._[0]) errorOutput('You must provide an image');
// Call the module
require('./index')(argv._[0], options).then(console.log).catch(errorOutput);