time-to-botec

Benchmark sampling in different programming languages
Log | Files | Refs | README

cli (2165B)


      1 #!/usr/bin/env node
      2 
      3 /**
      4 * @license Apache-2.0
      5 *
      6 * Copyright (c) 2018 The Stdlib Authors.
      7 *
      8 * Licensed under the Apache License, Version 2.0 (the "License");
      9 * you may not use this file except in compliance with the License.
     10 * You may obtain a copy of the License at
     11 *
     12 *    http://www.apache.org/licenses/LICENSE-2.0
     13 *
     14 * Unless required by applicable law or agreed to in writing, software
     15 * distributed under the License is distributed on an "AS IS" BASIS,
     16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     17 * See the License for the specific language governing permissions and
     18 * limitations under the License.
     19 */
     20 
     21 'use strict';
     22 
     23 // MODULES //
     24 
     25 var resolve = require( 'path' ).resolve;
     26 var readFileSync = require( '@stdlib/fs/read-file' ).sync;
     27 var CLI = require( '@stdlib/cli/ctor' );
     28 var parallel = require( './../lib' );
     29 
     30 
     31 // FUNCTIONS //
     32 
     33 /**
     34 * Callback invoked upon executing all scripts.
     35 *
     36 * @private
     37 * @param {Error} [error] - error object
     38 * @throws {Error} unexpected error
     39 */
     40 function done( error ) {
     41 	if ( error ) {
     42 		throw error;
     43 	}
     44 }
     45 
     46 
     47 // MAIN //
     48 
     49 /**
     50 * Main execution sequence.
     51 *
     52 * @private
     53 */
     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 provided command-line options:
     70 	flags = cli.flags();
     71 	if ( flags.help || flags.version ) {
     72 		return;
     73 	}
     74 
     75 	// Get any command-line arguments:
     76 	args = cli.args();
     77 
     78 	opts = {};
     79 	if ( flags.cmd ) {
     80 		opts.cmd = flags.cmd;
     81 	}
     82 	if ( flags.workers ) {
     83 		opts.workers = parseInt( flags.workers, 10 );
     84 	}
     85 	if ( flags.concurrency ) {
     86 		opts.concurrency = parseInt( flags.concurrency, 10 );
     87 	}
     88 	if ( flags.ordered ) {
     89 		opts.ordered = flags.ordered;
     90 	}
     91 	if ( flags.uid ) {
     92 		opts.uid = parseInt( flags.uid, 10 );
     93 	}
     94 	if ( flags.gid ) {
     95 		opts.gid = parseInt( flags.gid, 10 );
     96 	}
     97 	if ( flags.maxbuffer ) {
     98 		opts.maxBuffer = parseInt( flags.maxbuffer, 10 );
     99 	}
    100 
    101 	// Run main:
    102 	parallel( args, opts, done );
    103 }
    104 
    105 main();