Skip to content

Commit dc40fff

Browse files
committed
Merge pull request #21 from eGavr/logging
Refactoring
2 parents 336977e + 1870ace commit dc40fff

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

lib/cli.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,21 +66,22 @@ module.exports = require('coa').Cmd()
6666
.then(function (source) {
6767
if (opts.clean) return tocClean(source);
6868

69-
if (source.indexOf(TOC_COMMENT) === -1) return 'NO TOC COMMENT';
69+
if (source.indexOf(TOC_COMMENT) === -1) {
70+
log.noTocCommentErr();
71+
process.exit(1);
72+
}
7073

7174
var options = _.pick(opts, ['maxDepth', 'bullet']);
7275
return tocInsert(source, options);
76+
}, function () {
77+
log.noFileErr(args.source);
78+
process.exit(1);
7379
})
7480
.then(function (res) {
75-
if (res === 'NO TOC COMMENT') return log.noTocCommentErr();
76-
7781
return vfs.write(target, res)
7882
.then(function () {
7983
opts.clean ? log.successCleanMsg() : log.successInsertMsg();
8084
});
81-
})
82-
.fail(function (err) {
83-
console.log(err);
8485
});
8586
})
8687
.run(process.argv.slice(2));

lib/log.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@ module.exports = {
1111
},
1212

1313
noTocCommentErr: function () {
14-
console.log('A TOC generation ' + 'failed'.bold.red +
14+
console.error('A TOC generation ' + 'failed'.bold.red +
1515
'. Can not find the HTML comment ' + '<!-- TOC -->'.bold.red + '.');
16+
},
17+
18+
noFileErr: function (filepath) {
19+
console.error('A TOC generation ' + 'failed'.bold.red +
20+
'. Can not open file ' + filepath.underline + '.');
1621
}
1722
};

0 commit comments

Comments
 (0)