Skip to content

Commit 0019a20

Browse files
authored
Merge pull request #504 from domsleee/cli-add-dist-error-message
Add error message when --dist is not specified.
2 parents 7cbfcb3 + 6c1c6ad commit 0019a20

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

bin/gh-pages.js

+11-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
#!/usr/bin/env node
22

33
const ghpages = require('../lib/index.js');
4-
const program = require('commander');
4+
const {Command} = require('commander');
55
const path = require('path');
66
const pkg = require('../package.json');
77
const addr = require('email-addresses');
88

9-
function publish(config) {
9+
function publish(program, config) {
1010
return new Promise((resolve, reject) => {
11+
if (program.dist === undefined) {
12+
return reject(
13+
new Error(
14+
'No base directory specified. The `--dist` option must be specified.'
15+
)
16+
);
17+
}
1118
const basePath = path.resolve(process.cwd(), program.dist);
1219
ghpages.publish(basePath, config, (err) => {
1320
if (err) {
@@ -20,7 +27,7 @@ function publish(config) {
2027

2128
function main(args) {
2229
return Promise.resolve().then(() => {
23-
program
30+
const program = new Command()
2431
.version(pkg.version)
2532
.option('-d, --dist <dist>', 'Base directory for all source files')
2633
.option(
@@ -125,7 +132,7 @@ function main(args) {
125132
beforeAdd: beforeAdd,
126133
};
127134

128-
return publish(config);
135+
return publish(program, config);
129136
});
130137
}
131138

test/bin/gh-pages.spec.js

+5
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@ describe('gh-pages', () => {
8888
error:
8989
'Could not parse name and email from user option "junk email" (format should be "Your Name <[email protected]>")',
9090
},
91+
{
92+
args: ['.'],
93+
error:
94+
'No base directory specified. The `--dist` option must be specified.',
95+
},
9196
];
9297

9398
scenarios.forEach(({args, dist, config, error}) => {

0 commit comments

Comments
 (0)