Skip to content

Commit 3947a36

Browse files
committed
Refactor snippet
1 parent 7d2bbb7 commit 3947a36

File tree

1 file changed

+38
-17
lines changed
  • tools/snippets/bin

1 file changed

+38
-17
lines changed

tools/snippets/bin/cli

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,42 @@ var opts = require( './opts.json' );
1212
var TODO = require( './../lib' );
1313

1414

15+
// FUNCTIONS //
16+
17+
/**
18+
* Prints usage information.
19+
*
20+
* @private
21+
* @example
22+
* help();
23+
* // => '...'
24+
*/
25+
function help() {
26+
var fpath = path.join( __dirname, 'usage.txt' );
27+
fs.createReadStream( fpath )
28+
.pipe( process.stdout )
29+
.on( 'close', onClose );
30+
31+
function onClose() {
32+
process.exit( 0 );
33+
}
34+
} // end FUNCTION help()
35+
36+
/**
37+
* Prints the package version.
38+
*
39+
* @private
40+
* @example
41+
* version();
42+
* // => '#.#.#'
43+
*/
44+
function version() {
45+
var msg = pkg.version.toString()+'\n';
46+
process.stdout.write( msg, 'utf8' );
47+
process.exit( 0 );
48+
} // end FUNCTION version()
49+
50+
1551
// VARIABLES //
1652

1753
var args;
@@ -32,26 +68,11 @@ notifier( { 'pkg': pkg } ).notify();
3268

3369
args = parseArgs( process.argv.slice( 2 ), opts );
3470

35-
36-
// HELP //
37-
38-
function onClose() {
39-
process.exit( 0 );
40-
}
41-
4271
if ( args.help ) {
43-
fs.createReadStream( path.join( __dirname, 'usage.txt' ) )
44-
.pipe( process.stdout )
45-
.on( 'close', onClose );
46-
return;
72+
return help();
4773
}
48-
49-
50-
// VERSION //
51-
5274
if ( args.version ) {
53-
console.log( pkg.version );
54-
return;
75+
return version();
5576
}
5677

5778

0 commit comments

Comments
 (0)