Skip to content

Commit 0cb56ec

Browse files
committed
Update CLI
1 parent 7e06253 commit 0cb56ec

File tree

5 files changed

+264
-89
lines changed

5 files changed

+264
-89
lines changed

lib/node_modules/@stdlib/string/uncapitalize/README.md

+10-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ out = uncapitalize( 'Hidden Treasures' );
6767
### Usage
6868

6969
``` bash
70-
Usage: uncapitalize [options] <string>
70+
Usage: uncapitalize [options] [<string>]
7171

7272
Options:
7373

@@ -89,6 +89,13 @@ $ uncapitalize Beep
8989
beep
9090
```
9191

92+
To use as a [standard stream][standard-streams],
93+
94+
``` bash
95+
$ echo -n 'Beep' | uncapitalize
96+
beep
97+
```
98+
9299
</section>
93100

94101
<!-- /.examples -->
@@ -100,6 +107,8 @@ beep
100107

101108
<section class="links">
102109

110+
[standard-streams]: https://en.wikipedia.org/wiki/Standard_streams
111+
103112
</section>
104113

105114
<!-- /.links -->

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

100644100755
+39-87
Original file line numberDiff line numberDiff line change
@@ -3,109 +3,61 @@
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' );
6+
var join = require( 'path' ).join;
7+
var readFileSync = require( '@stdlib/fs/read-file' ).sync;
8+
var CLI = require( '@stdlib/tools/cli' );
9+
var stdin = require( '@stdlib/utils/read-stdin' );
1210
var uncapitalize = require( './../lib' );
1311

1412

1513
// FUNCTIONS //
1614

1715
/**
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.
16+
* Callback invoked upon reading from `stdin`.
4017
*
4118
* @private
42-
* @example
43-
* help();
44-
* // => '...'
19+
* @param {(Error|null)} error - error object
20+
* @param {Buffer} data - data
21+
* @returns {void}
4522
*/
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 );
23+
function onRead( error, data ) {
24+
/* eslint-disable no-console */
25+
if ( error ) {
26+
process.exitCode = 1;
27+
return console.error( 'Error: %s', error.message );
5428
}
55-
} // end FUNCTION help()
56-
57-
/**
58-
* Prints the package version.
59-
*
60-
* @private
61-
* @example
62-
* version();
63-
* // => '#.#.#'
64-
*/
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;
29+
console.log( uncapitalize( data.toString() ) );
30+
} // end FUNCTION onRead()
7531

7632

7733
// MAIN //
7834

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-
91-
// Check if we are receiving data from `stdin`...
92-
if ( !process.stdin.isTTY ) {
93-
return stdin( onRead );
94-
}
95-
console.log( uncapitalize( args._[0] ) );
96-
9735
/**
98-
* Callback invoked upon reading from `stdin`.
36+
* Main execution sequence.
9937
*
10038
* @private
101-
* @param {(Error|null)} error - error object
102-
* @param {Buffer} data - data
39+
* @returns {void}
10340
*/
104-
function onRead( error, data ) {
105-
var str;
106-
if ( error ) {
107-
return done( error );
41+
function main() {
42+
var args;
43+
var cli;
44+
45+
// Create a command-line interface:
46+
cli = new CLI({
47+
'pkg': require( './../package.json' ),
48+
'options': require( './opts.json' ),
49+
'help': readFileSync( join( __dirname, 'usage.txt' ), {
50+
'encoding': 'utf8'
51+
})
52+
});
53+
// Get any provided command-line arguments:
54+
args = cli.args();
55+
56+
// Check if we are receiving data from `stdin`...
57+
if ( !process.stdin.isTTY ) {
58+
return stdin( onRead );
10859
}
109-
str = uncapitalize( data.toString() );
110-
console.log( str );
111-
} // end FUNCTION onRead()
60+
console.log( uncapitalize( args[ 0 ] ) ); // eslint-disable-line no-console
61+
} // end FUNCTION main()
62+
63+
main();

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

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

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

44
Options:
55

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
var resolve = require( 'path' ).resolve;
2+
var proxyquire = require( 'proxyquire' );
3+
4+
var fpath = resolve( __dirname, '..', 'bin', 'cli' );
5+
6+
process.stdin.isTTY = false;
7+
8+
proxyquire( fpath, {
9+
'@stdlib/utils/read-stdin': stdin
10+
});
11+
12+
function stdin( clbk ) {
13+
clbk( new Error( 'BEEP' ) );
14+
}

0 commit comments

Comments
 (0)