Skip to content

Commit a8ce204

Browse files
committed
run prettier
1 parent 73ac1f7 commit a8ce204

12 files changed

+369
-373
lines changed

lib/command.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
'use strict';
1+
'use strict'
22

33
module.exports = function(usage, description, init, aliases) {
44
if (Array.isArray(init)) {
5-
aliases = init;
6-
init = undefined;
5+
aliases = init
6+
init = undefined
77
}
88
if (aliases && Array.isArray(aliases)) {
9-
usage = [].concat([usage], aliases);
9+
usage = [].concat([usage], aliases)
1010
}
1111

1212
// Register command to global scope
1313
this.details.commands.push({
1414
usage,
1515
description,
1616
init: typeof init === 'function' ? init : false
17-
});
17+
})
1818

1919
// Allow chaining of .command()
20-
return this;
21-
};
20+
return this
21+
}

lib/example.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
'use strict';
1+
'use strict'
22

33
module.exports = function(usage, description) {
44
if (typeof usage !== 'string' || typeof description !== 'string') {
55
throw new TypeError(
66
'Usage for adding an Example: args.example("usage", "description")'
7-
);
7+
)
88
}
9-
this.details.examples.push({ usage, description });
9+
this.details.examples.push({ usage, description })
1010

11-
return this;
12-
};
11+
return this
12+
}

lib/examples.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
'use strict';
1+
'use strict'
22

33
module.exports = function(list) {
44
if (list.constructor !== Array) {
5-
throw new Error('Item passed to .examples is not an array');
5+
throw new Error('Item passed to .examples is not an array')
66
}
77

88
for (const item of list) {
9-
const usage = item.usage || false;
10-
const description = item.description || false;
11-
this.example(usage, description);
9+
const usage = item.usage || false
10+
const description = item.description || false
11+
this.example(usage, description)
1212
}
1313

14-
return this;
15-
};
14+
return this
15+
}

lib/help.js

+24-24
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,76 @@
1-
'use strict';
1+
'use strict'
22

33
module.exports = function() {
4-
const name = this.config.name || this.binary.replace('-', ' ');
5-
const firstBig = word => word.charAt(0).toUpperCase() + word.substr(1);
4+
const name = this.config.name || this.binary.replace('-', ' ')
5+
const firstBig = word => word.charAt(0).toUpperCase() + word.substr(1)
66

7-
const parts = [];
7+
const parts = []
88

99
const groups = {
1010
commands: true,
1111
options: true,
1212
examples: true
13-
};
13+
}
1414

1515
for (const group in groups) {
1616
if (this.details[group].length > 0) {
17-
continue;
17+
continue
1818
}
1919

20-
groups[group] = false;
20+
groups[group] = false
2121
}
2222

23-
const optionHandle = groups.options ? '[options] ' : '';
24-
const cmdHandle = groups.commands ? '[command]' : '';
23+
const optionHandle = groups.options ? '[options] ' : ''
24+
const cmdHandle = groups.commands ? '[command]' : ''
2525
const value =
26-
typeof this.config.value === 'string' ? ' ' + this.config.value : '';
26+
typeof this.config.value === 'string' ? ' ' + this.config.value : ''
2727

2828
parts.push([
2929
'',
3030
`Usage: ${this.printMainColor(name)} ${this.printSubColor(
3131
optionHandle + cmdHandle + value
3232
)}`,
3333
''
34-
]);
34+
])
3535

3636
for (const group in groups) {
3737
if (!groups[group]) {
38-
continue;
38+
continue
3939
}
4040

41-
parts.push(['', firstBig(group) + ':', '', '']);
41+
parts.push(['', firstBig(group) + ':', '', ''])
4242

4343
if (group === 'examples') {
44-
parts.push(this.generateExamples());
44+
parts.push(this.generateExamples())
4545
} else {
46-
parts.push(this.generateDetails(group));
46+
parts.push(this.generateDetails(group))
4747
}
4848

49-
parts.push(['', '']);
49+
parts.push(['', ''])
5050
}
5151

52-
let output = '';
52+
let output = ''
5353

5454
// And finally, merge and output them
5555
for (const part of parts) {
56-
output += part.join('\n ');
56+
output += part.join('\n ')
5757
}
5858

5959
if (!groups.commands && !groups.options) {
60-
output = 'No sub commands or options available';
60+
output = 'No sub commands or options available'
6161
}
6262

63-
const usageFilter = this.config.usageFilter;
63+
const usageFilter = this.config.usageFilter
6464

6565
// If filter is available, pass usage information through
6666
if (typeof usageFilter === 'function') {
67-
output = usageFilter(output) || output;
67+
output = usageFilter(output) || output
6868
}
6969

70-
console.log(output);
70+
console.log(output)
7171

7272
if (this.config.exit && this.config.exit.help) {
7373
// eslint-disable-next-line unicorn/no-process-exit
74-
process.exit();
74+
process.exit()
7575
}
76-
};
76+
}

lib/index.js

+13-13
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
'use strict';
1+
'use strict'
22

3-
const chalk = require('chalk');
4-
const utils = require('./utils');
3+
const chalk = require('chalk')
4+
const utils = require('./utils')
55

66
const publicMethods = {
77
option: require('./option'),
@@ -12,14 +12,14 @@ const publicMethods = {
1212
examples: require('./examples'),
1313
showHelp: require('./help'),
1414
showVersion: require('./version')
15-
};
15+
}
1616

1717
function Args() {
1818
this.details = {
1919
options: [],
2020
commands: [],
2121
examples: []
22-
};
22+
}
2323

2424
// Configuration defaults
2525
this.config = {
@@ -31,28 +31,28 @@ function Args() {
3131
name: null,
3232
mainColor: 'yellow',
3333
subColor: 'dim'
34-
};
34+
}
3535

36-
this.printMainColor = chalk;
37-
this.printSubColor = chalk;
36+
this.printMainColor = chalk
37+
this.printSubColor = chalk
3838
}
3939

4040
// Assign internal helpers
4141
for (const util in utils) {
4242
if (!{}.hasOwnProperty.call(utils, util)) {
43-
continue;
43+
continue
4444
}
4545

46-
Args.prototype[util] = utils[util];
46+
Args.prototype[util] = utils[util]
4747
}
4848

4949
// Assign public methods
5050
for (const method in publicMethods) {
5151
if (!{}.hasOwnProperty.call(publicMethods, method)) {
52-
continue;
52+
continue
5353
}
5454

55-
Args.prototype[method] = publicMethods[method];
55+
Args.prototype[method] = publicMethods[method]
5656
}
5757

58-
module.exports = new Args();
58+
module.exports = new Args()

lib/option.js

+25-25
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,65 @@
1-
'use strict';
1+
'use strict'
22

33
module.exports = function(name, description, defaultValue, init) {
4-
let usage = [];
4+
let usage = []
55

66
const assignShort = (name, options, short) => {
77
if (options.find(flagName => flagName.usage[0] === short)) {
8-
short = name.charAt(0).toUpperCase();
8+
short = name.charAt(0).toUpperCase()
99
}
10-
return [short, name];
11-
};
10+
return [short, name]
11+
}
1212

1313
// If name is an array, pick the values
1414
// Otherwise just use the whole thing
1515
switch (name.constructor) {
1616
case String:
17-
usage = assignShort(name, this.details.options, name.charAt(0));
18-
break;
17+
usage = assignShort(name, this.details.options, name.charAt(0))
18+
break
1919
case Array:
20-
usage = usage.concat(name);
21-
break;
20+
usage = usage.concat(name)
21+
break
2222
default:
23-
throw new Error('Invalid name for option');
23+
throw new Error('Invalid name for option')
2424
}
2525

2626
// Throw error if short option is too long
2727
if (usage.length > 0 && usage[0].length > 1) {
28-
throw new Error('Short version of option is longer than 1 char');
28+
throw new Error('Short version of option is longer than 1 char')
2929
}
3030

3131
const optionDetails = {
3232
defaultValue,
3333
usage,
3434
description
35-
};
35+
}
3636

37-
let defaultIsWrong;
37+
let defaultIsWrong
3838

3939
switch (defaultValue) {
4040
case false:
41-
defaultIsWrong = true;
42-
break;
41+
defaultIsWrong = true
42+
break
4343
case null:
44-
defaultIsWrong = true;
45-
break;
44+
defaultIsWrong = true
45+
break
4646
case undefined:
47-
defaultIsWrong = true;
48-
break;
47+
defaultIsWrong = true
48+
break
4949
default:
50-
defaultIsWrong = false;
50+
defaultIsWrong = false
5151
}
5252

5353
if (typeof init === 'function') {
54-
optionDetails.init = init;
54+
optionDetails.init = init
5555
} else if (!defaultIsWrong) {
5656
// Set initializer depending on type of default value
57-
optionDetails.init = this.handleType(defaultValue)[1];
57+
optionDetails.init = this.handleType(defaultValue)[1]
5858
}
5959

6060
// Register option to global scope
61-
this.details.options.push(optionDetails);
61+
this.details.options.push(optionDetails)
6262

6363
// Allow chaining of .option()
64-
return this;
65-
};
64+
return this
65+
}

lib/options.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
'use strict';
1+
'use strict'
22

33
module.exports = function(list) {
44
if (list.constructor !== Array) {
5-
throw new Error('Item passed to .options is not an array');
5+
throw new Error('Item passed to .options is not an array')
66
}
77

88
for (const item of list) {
9-
const preset = item.defaultValue;
10-
const init = item.init || false;
9+
const preset = item.defaultValue
10+
const init = item.init || false
1111

12-
this.option(item.name, item.description, preset, init);
12+
this.option(item.name, item.description, preset, init)
1313
}
1414

15-
return this;
16-
};
15+
return this
16+
}

0 commit comments

Comments
 (0)