Skip to content

Commit c65a9e4

Browse files
committed
Update CLI snippet
1 parent 3215f91 commit c65a9e4

File tree

1 file changed

+25
-78
lines changed
  • tools/snippets/bin

1 file changed

+25
-78
lines changed

tools/snippets/bin/cli

Lines changed: 25 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -3,88 +3,35 @@
33

44
// MODULES //
55

6-
var fs = require( 'fs' );
7-
var path = require( 'path' );
8-
var parseArgs = require( 'minimist' );
9-
var notifier = require( 'update-notifier' );
10-
var pkg = require( './../package.json' );
11-
var opts = require( './opts.json' );
12-
var main = require( './../lib' );
6+
var join = require( 'path' ).join;
7+
var readFileSync = require( '@stdlib/fs/read-file' ).sync;
8+
var CLI = require( '@stdlib/tools/cli' );
9+
var foo = require( './../lib' );
1310

1411

15-
// FUNCTIONS //
16-
17-
/**
18-
* Performs initialization tasks.
19-
*
20-
* @private
21-
* @example
22-
* init();
23-
*/
24-
function init() {
25-
var opts;
26-
27-
// Check if newer versions exist for this package:
28-
opts = {
29-
'pkg': pkg
30-
};
31-
notifier( opts ).notify();
32-
33-
// Set the process title to allow the process to be more easily identified:
34-
process.title = pkg.name;
35-
process.stdout.on( 'error', process.exit );
36-
} // end FUNCTION init()
37-
38-
/**
39-
* Prints usage information.
40-
*
41-
* @private
42-
* @example
43-
* help();
44-
* // => '...'
45-
*/
46-
function help() {
47-
var fpath = path.join( __dirname, 'usage.txt' );
48-
fs.createReadStream( fpath )
49-
.pipe( process.stdout )
50-
.on( 'close', onClose );
51-
52-
function onClose() {
53-
process.exit( 0 );
54-
}
55-
} // end FUNCTION help()
12+
// MAIN //
5613

5714
/**
58-
* Prints the package version.
15+
* Main execution sequence.
5916
*
6017
* @private
61-
* @example
62-
* version();
63-
* // => '#.#.#'
6418
*/
65-
function version() {
66-
var msg = pkg.version.toString()+'\n';
67-
process.stdout.write( msg, 'utf8' );
68-
process.exit( 0 );
69-
} // end FUNCTION version()
70-
71-
72-
// VARIABLES //
73-
74-
var args;
75-
76-
77-
// MAIN //
78-
79-
init();
80-
81-
// Parse command-line arguments:
82-
args = parseArgs( process.argv.slice( 2 ), opts );
83-
84-
if ( args.help ) {
85-
return help();
86-
}
87-
if ( args.version ) {
88-
return version();
89-
}
90-
main(); // TODO: implementation
19+
function main() {
20+
var args;
21+
var cli;
22+
23+
// Create a command-line interface:
24+
cli = new CLI({
25+
'pkg': require( './../package.json' ),
26+
'options': require( './opts.json' ),
27+
'help': readFileSync( join( __dirname, 'usage.txt' ), {
28+
'encoding': 'utf8'
29+
})
30+
});
31+
// Get any provided command-line arguments:
32+
args = cli.args();
33+
34+
foo( args[ 0 ] ); // TODO: implementation
35+
} // end FUNCTION main()
36+
37+
main();

0 commit comments

Comments
 (0)