Skip to content

Commit e6cc5b0

Browse files
committed
Update CLIs
1 parent 5b81867 commit e6cc5b0

File tree

20 files changed

+402
-342
lines changed
  • lib/node_modules/@stdlib/string
    • left-pad/bin
    • left-trim/bin
    • lowercase/bin
    • pad/bin
    • percent-encode/bin
    • remove-first/bin
    • remove-last/bin
    • remove-punctuation/bin
    • remove-utf8-bom/bin
    • remove-words/bin
    • repeat/bin
    • replace/bin
    • reverse/bin
    • right-pad/bin
    • right-trim/bin
    • startcase/bin
    • starts-with/bin
    • trim/bin
    • uncapitalize/bin
    • uppercase/bin

20 files changed

+402
-342
lines changed

lib/node_modules/@stdlib/string/left-pad/bin/cli

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,15 @@ function main() {
5454
'encoding': 'utf8'
5555
})
5656
});
57-
args = cli.args();
57+
58+
// Get any provided command-line options:
5859
flags = cli.flags();
60+
if ( flags.help || flags.version ) {
61+
return;
62+
}
63+
64+
// Get any provided command-line arguments:
65+
args = cli.args();
5966

6067
if ( args.length ) {
6168
str = args[ 0 ];
@@ -64,7 +71,7 @@ function main() {
6471
str = '';
6572
}
6673
len = parseInt( flags.len, 10 );
67-
pad = flags.pad ? flags.pad : ' ';
74+
pad = flags.pad || ' ';
6875

6976
// Check if we are receiving data from `stdin`...
7077
if ( !process.stdin.isTTY ) {
@@ -81,16 +88,14 @@ function main() {
8188
* @returns {void}
8289
*/
8390
function onRead( error, data ) {
84-
/* eslint-disable no-console */
8591
var lines;
8692
var i;
8793
if ( error ) {
88-
process.exitCode = 1;
89-
return console.error( 'Error: %s', error.message );
94+
return cli.error( error );
9095
}
9196
lines = data.toString().split( RE_EOL );
9297
for ( i = 0; i < lines.length; i++ ) {
93-
console.log( lpad( lines[ i ], len, pad ) );
98+
console.log( lpad( lines[ i ], len, pad ) ); // eslint-disable-line no-console
9499
}
95100
}
96101
}

lib/node_modules/@stdlib/string/left-trim/bin/cli

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -30,31 +30,6 @@ var RE_EOL = require( '@stdlib/regexp/eol' );
3030
var ltrim = require( './../lib' );
3131

3232

33-
// FUNCTIONS //
34-
35-
/**
36-
* Callback invoked upon reading from `stdin`.
37-
*
38-
* @private
39-
* @param {(Error|null)} error - error object
40-
* @param {Buffer} data - data
41-
* @returns {void}
42-
*/
43-
function onRead( error, data ) {
44-
/* eslint-disable no-console */
45-
var lines;
46-
var i;
47-
if ( error ) {
48-
process.exitCode = 1;
49-
return console.error( 'Error: %s', error.message );
50-
}
51-
lines = data.toString().split( RE_EOL );
52-
for ( i = 0; i < lines.length; i++ ) {
53-
console.log( ltrim( lines[ i ] ) );
54-
}
55-
}
56-
57-
5833
// MAIN //
5934

6035
/**
@@ -64,6 +39,7 @@ function onRead( error, data ) {
6439
* @returns {void}
6540
*/
6641
function main() {
42+
var flags;
6743
var args;
6844
var cli;
6945

@@ -76,6 +52,12 @@ function main() {
7652
})
7753
});
7854

55+
// Get any provided command-line options:
56+
flags = cli.flags();
57+
if ( flags.help || flags.version ) {
58+
return;
59+
}
60+
7961
// Get any provided command-line arguments:
8062
args = cli.args();
8163

@@ -84,6 +66,26 @@ function main() {
8466
return stdin( onRead );
8567
}
8668
console.log( ltrim( args[ 0 ] ) ); // eslint-disable-line no-console
69+
70+
/**
71+
* Callback invoked upon reading from `stdin`.
72+
*
73+
* @private
74+
* @param {(Error|null)} error - error object
75+
* @param {Buffer} data - data
76+
* @returns {void}
77+
*/
78+
function onRead( error, data ) {
79+
var lines;
80+
var i;
81+
if ( error ) {
82+
return cli.error( error );
83+
}
84+
lines = data.toString().split( RE_EOL );
85+
for ( i = 0; i < lines.length; i++ ) {
86+
console.log( ltrim( lines[ i ] ) ); // eslint-disable-line no-console
87+
}
88+
}
8789
}
8890

8991
main();

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

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -29,26 +29,6 @@ var stdin = require( '@stdlib/process/read-stdin' );
2929
var lowercase = require( './../lib' );
3030

3131

32-
// FUNCTIONS //
33-
34-
/**
35-
* Callback invoked upon reading from `stdin`.
36-
*
37-
* @private
38-
* @param {(Error|null)} error - error object
39-
* @param {Buffer} data - data
40-
* @returns {void}
41-
*/
42-
function onRead( error, data ) {
43-
/* eslint-disable no-console */
44-
if ( error ) {
45-
process.exitCode = 1;
46-
return console.error( 'Error: %s', error.message );
47-
}
48-
console.log( lowercase( data.toString() ) );
49-
}
50-
51-
5232
// MAIN //
5333

5434
/**
@@ -58,6 +38,7 @@ function onRead( error, data ) {
5838
* @returns {void}
5939
*/
6040
function main() {
41+
var flags;
6142
var args;
6243
var cli;
6344

@@ -70,6 +51,12 @@ function main() {
7051
})
7152
});
7253

54+
// Get any provided command-line options:
55+
flags = cli.flags();
56+
if ( flags.help || flags.version ) {
57+
return;
58+
}
59+
7360
// Get any provided command-line arguments:
7461
args = cli.args();
7562

@@ -78,6 +65,21 @@ function main() {
7865
return stdin( onRead );
7966
}
8067
console.log( lowercase( args[ 0 ] ) ); // eslint-disable-line no-console
68+
69+
/**
70+
* Callback invoked upon reading from `stdin`.
71+
*
72+
* @private
73+
* @param {(Error|null)} error - error object
74+
* @param {Buffer} data - data
75+
* @returns {void}
76+
*/
77+
function onRead( error, data ) {
78+
if ( error ) {
79+
return cli.error( error );
80+
}
81+
console.log( lowercase( data.toString() ) ); // eslint-disable-line no-console
82+
}
8183
}
8284

8385
main();

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,15 @@ function main() {
5454
'encoding': 'utf8'
5555
})
5656
});
57-
args = cli.args();
57+
58+
// Get any provided command-line options:
5859
flags = cli.flags();
60+
if ( flags.help || flags.version ) {
61+
return;
62+
}
63+
64+
// Get any provided command-line arguments:
65+
args = cli.args();
5966

6067
if ( args.length ) {
6168
str = args[ 0 ];
@@ -90,16 +97,14 @@ function main() {
9097
* @returns {void}
9198
*/
9299
function onRead( error, data ) {
93-
/* eslint-disable no-console */
94100
var lines;
95101
var i;
96102
if ( error ) {
97-
process.exitCode = 1;
98-
return console.error( 'Error: %s', error.message );
103+
return cli.error( error );
99104
}
100105
lines = data.toString().split( RE_EOL );
101106
for ( i = 0; i < lines.length; i++ ) {
102-
console.log( pad( lines[ i ], len, opts ) );
107+
console.log( pad( lines[ i ], len, opts ) ); // eslint-disable-line no-console
103108
}
104109
}
105110
}

lib/node_modules/@stdlib/string/percent-encode/bin/cli

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -29,26 +29,6 @@ var stdin = require( '@stdlib/process/read-stdin' );
2929
var percentEncode = require( './../lib' );
3030

3131

32-
// FUNCTIONS //
33-
34-
/**
35-
* Callback invoked upon reading from `stdin`.
36-
*
37-
* @private
38-
* @param {(Error|null)} error - error object
39-
* @param {Buffer} data - data
40-
* @returns {void}
41-
*/
42-
function onRead( error, data ) {
43-
/* eslint-disable no-console */
44-
if ( error ) {
45-
process.exitCode = 1;
46-
return console.error( 'Error: %s', error.message );
47-
}
48-
console.log( percentEncode( data.toString() ) );
49-
}
50-
51-
5232
// MAIN //
5333

5434
/**
@@ -58,6 +38,7 @@ function onRead( error, data ) {
5838
* @returns {void}
5939
*/
6040
function main() {
41+
var flags;
6142
var args;
6243
var cli;
6344

@@ -70,6 +51,12 @@ function main() {
7051
})
7152
});
7253

54+
// Get any provided command-line options:
55+
flags = cli.flags();
56+
if ( flags.help || flags.version ) {
57+
return;
58+
}
59+
7360
// Get any provided command-line arguments:
7461
args = cli.args();
7562

@@ -78,6 +65,21 @@ function main() {
7865
return stdin( onRead );
7966
}
8067
console.log( percentEncode( args[ 0 ] ) ); // eslint-disable-line no-console
68+
69+
/**
70+
* Callback invoked upon reading from `stdin`.
71+
*
72+
* @private
73+
* @param {(Error|null)} error - error object
74+
* @param {Buffer} data - data
75+
* @returns {void}
76+
*/
77+
function onRead( error, data ) {
78+
if ( error ) {
79+
return cli.error( error );
80+
}
81+
console.log( percentEncode( data.toString() ) ); // eslint-disable-line no-console
82+
}
8183
}
8284

8385
main();

lib/node_modules/@stdlib/string/remove-first/bin/cli

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -30,31 +30,6 @@ var RE_EOL = require( '@stdlib/regexp/eol' );
3030
var removeFirst = require( './../lib' );
3131

3232

33-
// FUNCTIONS //
34-
35-
/**
36-
* Callback invoked upon reading from `stdin`.
37-
*
38-
* @private
39-
* @param {(Error|null)} error - error object
40-
* @param {Buffer} data - data
41-
* @returns {void}
42-
*/
43-
function onRead( error, data ) {
44-
/* eslint-disable no-console */
45-
var lines;
46-
var i;
47-
if ( error ) {
48-
process.exitCode = 1;
49-
return console.error( 'Error: %s', error.message );
50-
}
51-
lines = data.toString().split( RE_EOL );
52-
for ( i = 0; i < lines.length; i++ ) {
53-
console.log( removeFirst( lines[ i ] ) );
54-
}
55-
}
56-
57-
5833
// MAIN //
5934

6035
/**
@@ -64,6 +39,7 @@ function onRead( error, data ) {
6439
* @returns {void}
6540
*/
6641
function main() {
42+
var flags;
6743
var args;
6844
var cli;
6945

@@ -76,6 +52,12 @@ function main() {
7652
})
7753
});
7854

55+
// Get any provided command-line options:
56+
flags = cli.flags();
57+
if ( flags.help || flags.version ) {
58+
return;
59+
}
60+
7961
// Get any provided command-line arguments:
8062
args = cli.args();
8163

@@ -84,6 +66,26 @@ function main() {
8466
return stdin( onRead );
8567
}
8668
console.log( removeFirst( args[ 0 ] ) ); // eslint-disable-line no-console
69+
70+
/**
71+
* Callback invoked upon reading from `stdin`.
72+
*
73+
* @private
74+
* @param {(Error|null)} error - error object
75+
* @param {Buffer} data - data
76+
* @returns {void}
77+
*/
78+
function onRead( error, data ) {
79+
var lines;
80+
var i;
81+
if ( error ) {
82+
return cli.error( error );
83+
}
84+
lines = data.toString().split( RE_EOL );
85+
for ( i = 0; i < lines.length; i++ ) {
86+
console.log( removeFirst( lines[ i ] ) ); // eslint-disable-line no-console
87+
}
88+
}
8789
}
8890

8991
main();

0 commit comments

Comments
 (0)