Skip to content

Commit dbafed1

Browse files
committed
Update CLI
1 parent f1d976f commit dbafed1

File tree

2 files changed

+37
-90
lines changed

2 files changed

+37
-90
lines changed

lib/node_modules/@stdlib/string/lowercase/bin/cli

+36-89
Original file line numberDiff line numberDiff line change
@@ -3,112 +3,59 @@
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' );
6+
var join = require( 'path' ).join;
7+
var readFileSync = require( '@stdlib/fs/read-file' ).sync;
8+
var CLI = require( '@stdlib/tools/cli' );
109
var stdin = require( '@stdlib/utils/read-stdin' );
11-
var pkg = require( './../package.json' );
12-
var opts = require( './opts.json' );
1310
var lowercase = require( './../lib' );
1411

1512

1613
// FUNCTIONS //
1714

1815
/**
19-
* Performs initialization tasks.
20-
*
21-
* @private
22-
* @example
23-
* init();
24-
*/
25-
function init() {
26-
var opts;
27-
28-
// Check if newer versions exist for this package:
29-
opts = {
30-
'pkg': pkg
31-
};
32-
notifier( opts ).notify();
33-
34-
// Set the process title to allow the process to be more easily identified:
35-
process.title = pkg.name;
36-
process.stdout.on( 'error', process.exit );
37-
} // end FUNCTION init()
38-
39-
/**
40-
* Prints usage information.
16+
* Callback invoked upon reading from `stdin`.
4117
*
4218
* @private
43-
* @example
44-
* help();
45-
* // => '...'
19+
* @param {(Error|null)} error - error object
20+
* @param {Buffer} data - data
21+
* @returns {void}
4622
*/
47-
function help() {
48-
var fpath = path.join( __dirname, 'usage.txt' );
49-
fs.createReadStream( fpath )
50-
.pipe( process.stdout )
51-
.on( 'close', onClose );
52-
53-
function onClose() {
54-
process.exit( 0 );
23+
function onRead( error, data ) {
24+
if ( error ) {
25+
return console.error( error.message ); // eslint-disable-line no-console
5526
}
56-
} // end FUNCTION help()
57-
58-
/**
59-
* Prints the package version.
60-
*
61-
* @private
62-
* @example
63-
* version();
64-
* // => '#.#.#'
65-
*/
66-
function version() {
67-
var msg = pkg.version.toString()+'\n';
68-
process.stdout.write( msg, 'utf8' );
69-
process.exit( 0 );
70-
} // end FUNCTION version()
71-
72-
73-
// VARIABLES //
74-
75-
var args;
76-
var str;
27+
console.log( lowercase( data.toString() ) ); // eslint-disable-line no-console
28+
} // end FUNCTION onRead()
7729

7830

7931
// MAIN //
8032

81-
init();
82-
83-
// Parse command-line arguments:
84-
args = parseArgs( process.argv.slice( 2 ), opts );
85-
86-
if ( args.help ) {
87-
return help();
88-
}
89-
if ( args.version ) {
90-
return version();
91-
}
92-
93-
// Check if we are receiving data from `stdin`...
94-
if ( !process.stdin.isTTY ) {
95-
return stdin( onRead );
96-
}
97-
str = lowercase( args._[0] );
98-
console.log( str );
99-
10033
/**
101-
* Callback invoked upon reading from `stdin`.
34+
* Main execution sequence.
10235
*
10336
* @private
104-
* @param {(Error|null)} error - error object
105-
* @param {Buffer} data - data
37+
* @returns {void}
10638
*/
107-
function onRead( error, data ) {
108-
var str;
109-
if ( error ) {
110-
return done( error );
39+
function main() {
40+
var args;
41+
var cli;
42+
43+
// Create a command-line interface:
44+
cli = new CLI({
45+
'pkg': require( './../package.json' ),
46+
'options': require( './opts.json' ),
47+
'help': readFileSync( join( __dirname, 'usage.txt' ), {
48+
'encoding': 'utf8'
49+
})
50+
});
51+
// Get any provided command-line arguments:
52+
args = cli.args();
53+
54+
// Check if we are receiving data from `stdin`...
55+
if ( !process.stdin.isTTY ) {
56+
return stdin( onRead );
11157
}
112-
str = lowercase( data.toString() );
113-
console.log( str );
114-
} // end FUNCTION onRead()
58+
console.log( lowercase( args[ 0 ] ) ); // eslint-disable-line no-console
59+
} // end FUNCTION main()
60+
61+
main();

lib/node_modules/@stdlib/string/lowercase/bin/usage.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
Usage: lowercase [options] <string>
2+
Usage: lowercase [options] [<string>]
33

44
Options:
55

0 commit comments

Comments
 (0)