Skip to content
This repository was archived by the owner on Mar 23, 2024. It is now read-only.

Commit 051ff9a

Browse files
committed
Simplify cli module
1 parent 62a960f commit 051ff9a

File tree

1 file changed

+12
-30
lines changed

1 file changed

+12
-30
lines changed

lib/cli.js

Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ module.exports = function(program) {
2020
var promise = defer.promise();
2121
var checker = new Checker();
2222
var args = program.args;
23+
var returnArgs = {
24+
checker: checker,
25+
reporter: program.reporter,
26+
promise: promise
27+
};
2328

2429
promise.always(function(status) {
2530
process.exit(status.valueOf());
@@ -31,11 +36,7 @@ module.exports = function(program) {
3136
console.error('Config source is corrupted -', e.toString());
3237
defer.reject(1);
3338

34-
return {
35-
checker: checker,
36-
reporter: program.reporter,
37-
promise: promise
38-
};
39+
return returnArgs;
3940
}
4041

4142
/**
@@ -51,33 +52,21 @@ module.exports = function(program) {
5152

5253
defer.reject(1);
5354

54-
return {
55-
checker: checker,
56-
reporter: program.reporter,
57-
promise: promise
58-
};
55+
return returnArgs;
5956
}
6057

6158
if (program.preset && !preset.exists(program.preset)) {
6259
console.error(preset.getDoesNotExistError(program.preset));
6360
defer.reject(1);
6461

65-
return {
66-
checker: checker,
67-
reporter: program.reporter,
68-
promise: promise
69-
};
62+
return returnArgs;
7063
}
7164

7265
if (args.length === 0) {
7366
console.error('No input files specified. Try option --help for usage information.');
7467
defer.reject(1);
7568

76-
return {
77-
checker: checker,
78-
reporter: program.reporter,
79-
promise: promise
80-
};
69+
return returnArgs;
8170
}
8271

8372
if (!config) {
@@ -90,6 +79,7 @@ module.exports = function(program) {
9079

9180
if (program.reporter) {
9281
reporterPath = path.resolve(process.cwd(), program.reporter);
82+
returnArgs.reporter = reporterPath;
9383

9484
if (!fs.existsSync(reporterPath)) {
9585
reporterPath = './reporters/' + program.reporter;
@@ -106,11 +96,7 @@ module.exports = function(program) {
10696
console.error('Reporter "%s" doesn\'t exist.', reporterPath);
10797
defer.reject(1);
10898

109-
return {
110-
checker: checker,
111-
reporter: reporterPath,
112-
promise: promise
113-
};
99+
return returnArgs;
114100
}
115101

116102
checker.registerDefaultRules();
@@ -136,9 +122,5 @@ module.exports = function(program) {
136122
defer.reject(1);
137123
});
138124

139-
return {
140-
checker: checker,
141-
reporter: reporterPath,
142-
promise: promise
143-
};
125+
return returnArgs;
144126
};

0 commit comments

Comments
 (0)