Skip to content

Commit 0931e67

Browse files
committed
Update CLI
1 parent 2dd70c8 commit 0931e67

File tree

3 files changed

+58
-142
lines changed

3 files changed

+58
-142
lines changed

lib/node_modules/@stdlib/utils/parallel/bin/cli

Lines changed: 58 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -22,128 +22,82 @@
2222

2323
// MODULES //
2424

25-
var fs = require( 'fs' );
26-
var path = require( 'path' );
27-
var parseArgs = require( 'minimist' );
28-
var notifier = require( 'update-notifier' );
29-
var pkg = require( './../package.json' );
30-
var opts = require( './opts.json' );
25+
var resolve = require( 'path' ).resolve;
26+
var readFileSync = require( '@stdlib/fs/read-file' ).sync;
27+
var CLI = require( '@stdlib/tools/cli' );
3128
var parallel = require( './../lib' );
3229

3330

3431
// FUNCTIONS //
3532

3633
/**
37-
* Performs initialization tasks.
38-
*
39-
* @private
40-
* @example
41-
* init();
42-
*/
43-
function init() {
44-
var opts;
45-
46-
// Check if newer versions exist for this package:
47-
opts = {
48-
'pkg': pkg
49-
};
50-
notifier( opts ).notify();
51-
52-
// Set the process title to allow the process to be more easily identified:
53-
process.title = pkg.name;
54-
process.stdout.on( 'error', process.exit );
55-
}
56-
57-
/**
58-
* Prints usage information.
34+
* Callback invoked upon executing all scripts.
5935
*
6036
* @private
61-
* @example
62-
* help();
63-
* // => '...'
37+
* @param {Error} [error] - error object
38+
* @throws {Error} unexpected error
6439
*/
65-
function help() {
66-
var fpath = path.join( __dirname, 'usage.txt' );
67-
fs.createReadStream( fpath )
68-
.pipe( process.stdout )
69-
.on( 'close', onClose );
70-
71-
function onClose() {
72-
process.exit( 0 );
40+
function done( error ) {
41+
if ( error ) {
42+
throw error;
7343
}
7444
}
7545

76-
/**
77-
* Prints the package version.
78-
*
79-
* @private
80-
* @example
81-
* version();
82-
* // => '#.#.#'
83-
*/
84-
function version() {
85-
var msg = pkg.version.toString()+'\n';
86-
process.stdout.write( msg, 'utf8' );
87-
process.exit( 0 );
88-
}
89-
90-
91-
// VARIABLES //
92-
93-
var files;
94-
var args;
95-
9646

9747
// MAIN //
9848

99-
init();
100-
101-
// Parse command-line arguments:
102-
args = parseArgs( process.argv.slice( 2 ), opts );
103-
104-
if ( args.help ) {
105-
return help();
106-
}
107-
if ( args.version ) {
108-
return version();
109-
}
110-
111-
opts = {};
112-
if ( args.cmd ) {
113-
opts.cmd = args.cmd;
114-
}
115-
if ( args.workers ) {
116-
opts.workers = parseInt( args.workers, 10 );
117-
}
118-
if ( args.concurrency ) {
119-
opts.concurrency = parseInt( args.concurrency, 10 );
120-
}
121-
if ( args.ordered ) {
122-
opts.ordered = args.ordered;
123-
}
124-
if ( args.uid ) {
125-
opts.uid = parseInt( args.uid, 10 );
126-
}
127-
if ( args.gid ) {
128-
opts.gid = parseInt( args.gid, 10 );
129-
}
130-
if ( args.maxbuffer ) {
131-
opts.maxBuffer = parseInt( args.maxbuffer, 10 );
132-
}
133-
files = args._;
134-
135-
// Run main:
136-
parallel( files, opts, done );
137-
13849
/**
139-
* Callback invoked upon executing all scripts.
50+
* Main execution sequence.
14051
*
14152
* @private
142-
* @param {Error} [error] - error object
143-
* @throws {Error} unexpected error
14453
*/
145-
function done( error ) {
146-
if ( error ) {
147-
throw error;
54+
function main() {
55+
var flags;
56+
var args;
57+
var opts;
58+
var cli;
59+
60+
// Create a command-line interface:
61+
cli = new CLI({
62+
'pkg': require( './../package.json' ),
63+
'options': require( './../etc/cli_opts.json' ),
64+
'help': readFileSync( resolve( __dirname, '..', 'docs', 'usage.txt' ), {
65+
'encoding': 'utf8'
66+
})
67+
});
68+
69+
// Get any command-line arguments:
70+
args = cli.args();
71+
72+
// Get any command-line options:
73+
flags = cli.flags();
74+
75+
opts = {};
76+
if ( flags.cmd ) {
77+
opts.cmd = flags.cmd;
78+
}
79+
if ( flags.workers ) {
80+
opts.workers = parseInt( flags.workers, 10 );
81+
}
82+
if ( flags.concurrency ) {
83+
opts.concurrency = parseInt( flags.concurrency, 10 );
84+
}
85+
if ( flags.ordered ) {
86+
opts.ordered = flags.ordered;
14887
}
88+
if ( flags.uid ) {
89+
opts.uid = parseInt( flags.uid, 10 );
90+
}
91+
if ( flags.gid ) {
92+
opts.gid = parseInt( flags.gid, 10 );
93+
}
94+
if ( flags.maxbuffer ) {
95+
opts.maxBuffer = parseInt( flags.maxbuffer, 10 );
96+
}
97+
98+
// Run main:
99+
parallel( args, opts, done );
149100
}
101+
102+
main();
103+

lib/node_modules/@stdlib/utils/parallel/bin/opts.json

Lines changed: 0 additions & 23 deletions
This file was deleted.

lib/node_modules/@stdlib/utils/parallel/bin/usage.txt

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)