Skip to content

Commit cbc1f3e

Browse files
author
redaktice
committed
More mild approach
1 parent 94a1807 commit cbc1f3e

File tree

2 files changed

+264
-277
lines changed

2 files changed

+264
-277
lines changed

bin/express-cli.js

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,25 @@ const _exit = process.exit;
2121
// TODO: Switch to a different command framework
2222
process.exit = exit;
2323

24-
let _helpShown = false;
25-
2624
// CLI
2725

28-
around(program, 'optionMissingArgument', (fn, args) => {
26+
around(program, 'optionMissingArgument', function (fn, args) {
2927
program.outputHelp();
30-
fn(...args);
28+
fn.apply(this, args);
3129
return { args: [], unknown: [] };
3230
});
3331

34-
before(program, 'outputHelp', () => {
32+
before(program, 'outputHelp', function () {
3533
// track if help was shown for unknown option
36-
_helpShown = true;
34+
this._helpShown = true;
3735
});
3836

39-
before(program, 'unknownOption', () => {
37+
before(program, 'unknownOption', function () {
38+
// allow unknown options if help was shown, to prevent trailing error
39+
this._allowUnknownOption = this._helpShown;
40+
4041
// show help if not yet shown
41-
if (!_helpShown) {
42+
if (!this._helpShown) {
4243
program.outputHelp();
4344
}
4445
});
@@ -92,11 +93,11 @@ function around(obj, method, fn) {
9293
const old = obj[method];
9394

9495
obj[method] = function () {
95-
var args = new Array(arguments.length);
96+
const args = new Array(arguments.length);
9697
for (let i = 0; i < args.length; i++) {
9798
args[i] = arguments[i];
9899
}
99-
return fn(old, args);
100+
return fn.call(this, old, args);
100101
};
101102
}
102103

@@ -107,9 +108,9 @@ function around(obj, method, fn) {
107108
function before(obj, method, fn) {
108109
const old = obj[method];
109110

110-
obj[method] = () => {
111-
fn();
112-
old(...arguments);
111+
obj[method] = function () {
112+
fn.call(this);
113+
old.apply(this, arguments);
113114
};
114115
}
115116

@@ -161,7 +162,7 @@ function createApplication(name, dir) {
161162

162163
// Package
163164
const pkg = {
164-
name: name,
165+
name,
165166
version: '0.0.0',
166167
private: true,
167168
scripts: {
@@ -360,7 +361,7 @@ function createApplication(name, dir) {
360361
mkdir(dir, 'bin');
361362
write(path.join(dir, 'bin/www'), www.render(), MODE_0755);
362363

363-
var prompt = launchedFromCmd() ? '>' : '$';
364+
const prompt = launchedFromCmd() ? '>' : '$';
364365

365366
if (dir !== '.') {
366367
console.log();
@@ -501,7 +502,7 @@ function main() {
501502
}
502503

503504
// Generate application
504-
emptyDirectory(destinationPath, (empty) => {
505+
emptyDirectory(destinationPath, function (empty) {
505506
if (empty || program.force) {
506507
createApplication(appName, destinationPath);
507508
} else {
@@ -560,7 +561,7 @@ function renamedOption(originalName, newName) {
560561

561562
function warning(message) {
562563
console.error();
563-
message.split('\n').forEach((line) => {
564+
message.split('\n').forEach(function (line) {
564565
console.error(' warning: %s', line);
565566
});
566567
console.error();

0 commit comments

Comments
 (0)