Skip to content

Commit 2e03357

Browse files
committed
printing help whenever any error is caught
1 parent 2e10405 commit 2e03357

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

bin.js

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#!/usr/bin/env node
2-
require('yargs')
2+
const yargs = require('yargs')
33
.command(
44
'$0',
5-
'convert HEIC image to JPEG or PNG',
5+
'Convert HEIC image to JPEG or PNG',
66
yargs => yargs
77
.option('format', {
88
alias: 'f',
@@ -66,7 +66,7 @@ require('yargs')
6666
)
6767
.command(
6868
'info',
69-
'see minimum info about each image in the file',
69+
'See minimum info about each image in the file',
7070
(yargs) => yargs
7171
.option('input', {
7272
alias: 'i',
@@ -80,21 +80,20 @@ require('yargs')
8080
default: false
8181
}),
8282
async ({ input, count }) => {
83-
/* eslint-disable no-console */
8483
try {
8584
await new Promise(r => setTimeout(() => r(), 0));
8685
const images = await prep({ input });
8786

87+
// eslint-disable-next-line no-console
8888
console.log(count ? `${images.length}` : `images in file: ${images.length}`);
8989
} catch (err) {
90-
process.exitCode = 1;
91-
console.error(err);
90+
onError(err);
9291
}
93-
/* eslint-enable no-console */
9492
}
9593
)
96-
.help()
97-
.argv;
94+
.help();
95+
96+
yargs.argv;
9897

9998
const { promisify } = require('util');
10099
const fs = require('fs');
@@ -159,7 +158,8 @@ const outputAllImages = async ({ images, output }) => {
159158
};
160159

161160
const onError = err => {
162-
// eslint-disable-next-line no-console
163-
console.error(err);
161+
console.error(err); // eslint-disable-line no-console
162+
console.error(''); // eslint-disable-line no-console
163+
yargs.showHelp();
164164
process.exitCode = 1;
165165
};

0 commit comments

Comments
 (0)