Skip to content

Commit 92255d1

Browse files
committed
Cosmetic: prettify
1 parent c8657c3 commit 92255d1

13 files changed

+153
-127
lines changed

README.md

+86-60
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
# [shellcraft.js](https://www.npmjs.org/package/shellcraft)
32

43
[![npm version](https://badge.fury.io/js/shellcraft.svg)](http://badge.fury.io/js/shellcraft)
@@ -8,7 +7,7 @@
87

98
Simple CLI and shell for Node.js based on [commander][1] and [inquirer][2].
109

11-
This module provides a way in order to use *commander* and *inquirer* together.
10+
This module provides a way in order to use _commander_ and _inquirer_ together.
1211
There are a CLI and a shell mode, and the same commands can be used everywhere.
1312

1413
**shellcraft.js** supports the command history and the auto-completion (in shell
@@ -27,15 +26,15 @@ $ npm install shellcraft
2726
### Hello, World
2827

2928
```javascript
30-
var shellcraft = require ('shellcraft');
29+
var shellcraft = require('shellcraft');
3130

3231
var options = {
33-
version: '0.1.0'
32+
version: '0.1.0',
3433
};
3534

36-
shellcraft.begin (options, function (err, results) {
35+
shellcraft.begin(options, function (err, results) {
3736
if (results) {
38-
console.log (results);
37+
console.log(results);
3938
}
4039
});
4140
```
@@ -45,6 +44,7 @@ shellcraft.begin (options, function (err, results) {
4544
There are only two public API in order to play with shellcraft.
4645

4746
---
47+
4848
#### shellcraft.begin (options, callback)
4949

5050
✤ options
@@ -53,8 +53,8 @@ There are only two public API in order to play with shellcraft.
5353
options = {
5454
version: '0.1.0',
5555
prompt: '>',
56-
promptFixed: false
57-
}
56+
promptFixed: false,
57+
};
5858
```
5959

6060
The `version` is used by Commander with the `-V, --version` parameter.
@@ -78,17 +78,21 @@ mode. This behavior will change in the future.
7878
##### Example
7979

8080
```javascript
81-
shellcraft.begin ({
82-
version: '0.0.1',
83-
prompt: 'orc>'
84-
}, function (err, results) {
85-
if (results) {
86-
console.log (results);
81+
shellcraft.begin(
82+
{
83+
version: '0.0.1',
84+
prompt: 'orc>',
85+
},
86+
function (err, results) {
87+
if (results) {
88+
console.log(results);
89+
}
8790
}
88-
});
91+
);
8992
```
9093

9194
shell mode
95+
9296
```
9397
$ node myShell.js
9498
orc> _
@@ -102,6 +106,7 @@ $ _
102106
```
103107

104108
CLI mode
109+
105110
```
106111
$ node myShell.js -h
107112
@@ -117,6 +122,7 @@ $ _
117122
```
118123

119124
---
125+
120126
#### shellcraft.registerExtension (shellExt, callback);
121127

122128
There are two builtin commands `help` and `exit`. For more commands you must
@@ -128,11 +134,11 @@ export two functions (`register()` and `unregister()`).
128134
The path on the `.js` file where the `register` and `unregister` methods are
129135
exported. An `extension` argument is passed with the `register` call. This
130136
object has four methods, `command`, `option`, `remove` and `reload`. It looks
131-
like the *commander* API in some ways.
137+
like the _commander_ API in some ways.
132138

133139
```javascript
134140
extension
135-
.command ('foo', 'foo description', options, function (callback, args) {
141+
.command('foo', 'foo description', options, function (callback, args) {
136142
/*
137143
* callback (wizard, function (answers) {})
138144
* Is called in order to return to the prompt (or exit if CLI). The wizard
@@ -145,7 +151,7 @@ extension
145151
* Are the arguments provided with the command.
146152
*/
147153
})
148-
.option ('-f, --foo', 'foo description', options, function (callback, args) {
154+
.option('-f, --foo', 'foo description', options, function (callback, args) {
149155
/*
150156
* callback ()
151157
*
@@ -155,13 +161,14 @@ extension
155161
});
156162

157163
/* Remove a specific command or option */
158-
extension.remove ('foo');
164+
extension.remove('foo');
159165

160166
/* Reload for autocomplete (for example after removing a command) */
161-
extension.reload ();
167+
extension.reload();
162168
```
163169

164170
The options can be (for `command`):
171+
165172
```javascript
166173
options : {
167174
wizard : false, /* when it needs Inquirer */
@@ -188,6 +195,7 @@ options : {
188195
```
189196

190197
The options can be (for `option`):
198+
191199
```javascript
192200
options : {
193201
params : {
@@ -213,24 +221,26 @@ var cmd = {};
213221
var opt = {};
214222

215223
cmd.hello = function (callback, args) {
216-
console.log (zog + ' tells "Hello, ' + args.join (' ') + '"');
217-
callback ();
224+
console.log(zog + ' tells "Hello, ' + args.join(' ') + '"');
225+
callback();
218226
};
219227

220228
cmd.wizard = function (callback) {
221-
var wizard = [{
222-
/* Inquirer definition... */
223-
type: 'input',
224-
name: 'zog',
225-
message: 'tell ' + zog
226-
}];
227-
228-
callback (wizard, function (answers) {
229+
var wizard = [
230+
{
231+
/* Inquirer definition... */
232+
type: 'input',
233+
name: 'zog',
234+
message: 'tell ' + zog,
235+
},
236+
];
237+
238+
callback(wizard, function (answers) {
229239
/* stuff on answers */
230240
if (answers.zog === zog) {
231-
console.log (zog + ' ' + zog);
241+
console.log(zog + ' ' + zog);
232242
} else {
233-
console.log ('lokthar?');
243+
console.log('lokthar?');
234244
}
235245

236246
/*
@@ -249,34 +259,49 @@ opt.foobar = function (callback, args) {
249259
} else {
250260
zog = 'lokthar';
251261
}
252-
callback ();
262+
callback();
253263
};
254264

255265
exports.register = function (extension, callback) {
256266
extension
257-
.command ('hello', 'print Hello, John', {
258-
wizard: false,
259-
params: {
260-
required: 'name',
261-
optional: 'etc...'
262-
}
263-
}, cmd.hello)
264-
.command ('wizard', 'begins a wizard', {
265-
wizard: true,
266-
scope: 'warcraft'
267-
}, cmd.wizard)
268-
.option ('-f, --foobar', 'zog is foobar', {
269-
params: {
270-
required: 'who'
271-
}
272-
}, opt.foobar);
273-
274-
callback ();
267+
.command(
268+
'hello',
269+
'print Hello, John',
270+
{
271+
wizard: false,
272+
params: {
273+
required: 'name',
274+
optional: 'etc...',
275+
},
276+
},
277+
cmd.hello
278+
)
279+
.command(
280+
'wizard',
281+
'begins a wizard',
282+
{
283+
wizard: true,
284+
scope: 'warcraft',
285+
},
286+
cmd.wizard
287+
)
288+
.option(
289+
'-f, --foobar',
290+
'zog is foobar',
291+
{
292+
params: {
293+
required: 'who',
294+
},
295+
},
296+
opt.foobar
297+
);
298+
299+
callback();
275300
};
276301

277302
exports.unregister = function (callback) {
278303
/* internal stuff */
279-
callback ();
304+
callback();
280305
};
281306
```
282307

@@ -285,19 +310,19 @@ exports.unregister = function (callback) {
285310
```javascript
286311
'use strict';
287312

288-
var path = require ('path');
289-
var shellcraft = require ('../');
313+
var path = require('path');
314+
var shellcraft = require('../');
290315

291316
var options = {
292317
version: '0.0.1',
293-
prompt: 'orc>'
318+
prompt: 'orc>',
294319
};
295-
var shellExt = path.join (__dirname, 'myShellExtension.js');
320+
var shellExt = path.join(__dirname, 'myShellExtension.js');
296321

297-
shellcraft.registerExtension (shellExt, function () {
298-
shellcraft.begin (options, function (err, results) {
322+
shellcraft.registerExtension(shellExt, function () {
323+
shellcraft.begin(options, function (err, results) {
299324
if (results) {
300-
console.log (results);
325+
console.log(results);
301326
}
302327
});
303328
});
@@ -306,6 +331,7 @@ shellcraft.registerExtension (shellExt, function () {
306331
---
307332

308333
shell mode
334+
309335
```
310336
$ node myShell.js
311337
orc> _
@@ -322,6 +348,7 @@ $ _
322348
```
323349

324350
CLI mode
351+
325352
```
326353
$ node myShell.js -h
327354
@@ -402,6 +429,5 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
402429
SOFTWARE.
403430
```
404431

405-
406432
[1]: https://www.npmjs.org/package/commander
407433
[2]: https://www.npmjs.org/package/inquirer

examples/myShell.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ var options = {
1717
};
1818
var shellExt = path.join(__dirname, 'myShellExtension.js');
1919

20-
shellcraft.registerExtension(shellExt, function() {
21-
shellcraft.begin(options, function(err, results) {
20+
shellcraft.registerExtension(shellExt, function () {
21+
shellcraft.begin(options, function (err, results) {
2222
if (results) {
2323
console.log(results);
2424
}

examples/myShellExtension.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ var zog = 'zog';
1313
var cmd = {};
1414
var opt = {};
1515

16-
cmd.hello = function(callback, args) {
16+
cmd.hello = function (callback, args) {
1717
console.log(zog + ' tells "Hello, ' + args.join(' ') + '"');
1818
callback();
1919
};
2020

21-
cmd.wizard = function(callback) {
21+
cmd.wizard = function (callback) {
2222
var wizard = [
2323
{
2424
/* Inquirer definition... */
@@ -28,7 +28,7 @@ cmd.wizard = function(callback) {
2828
},
2929
];
3030

31-
callback(wizard, function(answers) {
31+
callback(wizard, function (answers) {
3232
/* stuff on answers */
3333
if (answers.zog === zog) {
3434
console.log(zog + ' ' + zog);
@@ -46,7 +46,7 @@ cmd.wizard = function(callback) {
4646
});
4747
};
4848

49-
opt.foobar = function(callback, args) {
49+
opt.foobar = function (callback, args) {
5050
if (args) {
5151
zog = args[0];
5252
} else {
@@ -55,7 +55,7 @@ opt.foobar = function(callback, args) {
5555
callback();
5656
};
5757

58-
exports.register = function(extension, callback) {
58+
exports.register = function (extension, callback) {
5959
extension
6060
.command(
6161
'hello',
@@ -137,7 +137,7 @@ exports.register = function(extension, callback) {
137137
callback();
138138
};
139139

140-
exports.unregister = function(callback) {
140+
exports.unregister = function (callback) {
141141
/* internal stuff */
142142
callback();
143143
};

0 commit comments

Comments
 (0)