time-to-botec

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

cli (1981B)


      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 lpad = require( '@stdlib/string/left-pad' );
     29 var umask = require( './../lib' );
     30 
     31 
     32 // MAIN //
     33 
     34 /**
     35 * Main execution sequence.
     36 *
     37 * @private
     38 * @returns {void}
     39 */
     40 function main() {
     41 	var flags;
     42 	var opts;
     43 	var cli;
     44 	var out;
     45 
     46 	// Create a command-line interface:
     47 	cli = new CLI({
     48 		'pkg': require( './../package.json' ),
     49 		'options': require( './../etc/cli_opts.json' ),
     50 		'help': readFileSync( resolve( __dirname, '..', 'docs', 'usage.txt' ), {
     51 			'encoding': 'utf8'
     52 		})
     53 	});
     54 
     55 	// Get any provided command-line options:
     56 	flags = cli.flags();
     57 	if ( flags.help || flags.version ) {
     58 		return;
     59 	}
     60 
     61 	opts = {};
     62 	if ( flags.symbolic ) {
     63 		opts.symbolic = flags.symbolic;
     64 	}
     65 
     66 	// Get the process `mask`:
     67 	out = umask( opts );
     68 
     69 	// Print the result:
     70 	if ( opts.symbolic ) {
     71 		out = out.toString();
     72 		if ( flags.print ) {
     73 			return console.log( 'umask -S %s', out ); // eslint-disable-line no-console
     74 		}
     75 		return console.log( out ); // eslint-disable-line no-console
     76 	}
     77 	out = lpad( out.toString( 8 ), 4, '0' );
     78 	if ( flags.print ) {
     79 		return console.log( 'umask %s', out ); // eslint-disable-line no-console
     80 	}
     81 	console.log( out ); // eslint-disable-line no-console
     82 }
     83 
     84 main();