Skip to content

Commit b7c1bc1

Browse files
committed
Update CLIs
1 parent e806750 commit b7c1bc1

File tree

7 files changed

+67
-42
lines changed
  • lib/node_modules/@stdlib/fs
    • exists/bin
    • read-dir/bin
    • read-file/bin
    • read-file-list/bin
    • rename/bin
    • unlink/bin
    • write-file/bin

7 files changed

+67
-42
lines changed

lib/node_modules/@stdlib/fs/exists/bin/cli

+8-2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ var exists = require( './../lib' );
3838
* @returns {void}
3939
*/
4040
function main() {
41+
var flags;
4142
var tpath;
4243
var args;
4344
var cli;
@@ -51,6 +52,12 @@ function main() {
5152
})
5253
});
5354

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

@@ -67,8 +74,7 @@ function main() {
6774
*/
6875
function onTest( error, bool ) {
6976
if ( error ) {
70-
console.error( error.message ); // eslint-disable-line no-console
71-
return cli.exit( 1 );
77+
return cli.error( error );
7278
}
7379
console.log( bool.toString() ); // eslint-disable-line no-console
7480
}

lib/node_modules/@stdlib/fs/read-dir/bin/cli

+8-2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ var readDir = require( './../lib' );
3838
* @returns {void}
3939
*/
4040
function main() {
41+
var flags;
4142
var dpath;
4243
var args;
4344
var cli;
@@ -51,6 +52,12 @@ function main() {
5152
})
5253
});
5354

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

@@ -67,8 +74,7 @@ function main() {
6774
*/
6875
function onRead( error, data ) {
6976
if ( error ) {
70-
console.error( error.message ); // eslint-disable-line no-console
71-
return cli.exit( 1 );
77+
return cli.error( error );
7278
}
7379
console.log( data.join( '\n' ) ); // eslint-disable-line no-console
7480
}

lib/node_modules/@stdlib/fs/read-file-list/bin/cli

+7-4
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,15 @@ function main() {
5454
})
5555
});
5656

57+
// Get any provided command-line options:
58+
flags = cli.flags();
59+
if ( flags.help || flags.version ) {
60+
return;
61+
}
62+
5763
// Get any provided command-line arguments:
5864
files = cli.args();
5965

60-
// Get any provided command-line options:
61-
flags = cli.flags();
6266
opts = {};
6367
if ( flags.encoding ) {
6468
opts.encoding = flags.encoding;
@@ -84,8 +88,7 @@ function main() {
8488
function onFiles( error, results ) {
8589
var i;
8690
if ( error ) {
87-
console.error( error.message ); // eslint-disable-line no-console
88-
return cli.exit( 1 );
91+
return cli.error( error );
8992
}
9093
for ( i = 0; i < results.length; i++ ) {
9194
results[ i ].data = results[ i ].data.toString();

lib/node_modules/@stdlib/fs/read-file/bin/cli

+7-5
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,14 @@ function main() {
5353
})
5454
});
5555

56-
// Get any provided command-line arguments:
57-
args = cli.args();
58-
5956
// Get any provided command-line options:
6057
flags = cli.flags();
58+
if ( flags.help || flags.version ) {
59+
return;
60+
}
61+
62+
// Get any provided command-line arguments:
63+
args = cli.args();
6164

6265
opts = {};
6366
if ( flags.encoding ) {
@@ -80,8 +83,7 @@ function main() {
8083
*/
8184
function onFile( error, file ) {
8285
if ( error ) {
83-
process.exitCode = 1;
84-
return console.error( 'Error: %s', error.message ); // eslint-disable-line no-console
86+
return cli.error( error );
8587
}
8688
console.log( file.toString() ); // eslint-disable-line no-console
8789
}

lib/node_modules/@stdlib/fs/rename/bin/cli

+9-4
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ var rename = require( './../lib' );
4040
function main() {
4141
var oldPath;
4242
var newPath;
43+
var flags;
4344
var args;
4445
var cli;
4546
var dir;
@@ -53,12 +54,17 @@ function main() {
5354
})
5455
});
5556

57+
// Get any provided command-line options:
58+
flags = cli.flags();
59+
if ( flags.help || flags.version ) {
60+
return;
61+
}
62+
5663
// Get any provided command-line arguments:
5764
args = cli.args();
5865

5966
if ( args.length !== 2 ) {
60-
process.exitCode = 1;
61-
return console.error( 'Error: invalid invocation. Must provide two arguments: an old path and a new path.' ); // eslint-disable-line no-console
67+
return cli.error( new Error( 'invalid invocation. Must provide two arguments: an old path and a new path.' ) );
6268
}
6369
dir = cwd();
6470
oldPath = resolve( dir, args[ 0 ] );
@@ -75,8 +81,7 @@ function main() {
7581
*/
7682
function done( error ) {
7783
if ( error ) {
78-
process.exitCode = 1;
79-
return console.error( 'Error: %s', error.message ); // eslint-disable-line no-console
84+
return cli.error( error );
8085
}
8186
}
8287
}

lib/node_modules/@stdlib/fs/unlink/bin/cli

+8-2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ var unlink = require( './../lib' );
3838
* @returns {void}
3939
*/
4040
function main() {
41+
var flags;
4142
var fpath;
4243
var args;
4344
var cli;
@@ -51,6 +52,12 @@ function main() {
5152
})
5253
});
5354

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

@@ -66,8 +73,7 @@ function main() {
6673
*/
6774
function done( error ) {
6875
if ( error ) {
69-
process.exitCode = 1;
70-
return console.error( 'Error: %s', error.message ); // eslint-disable-line no-console
76+
return cli.error( error );
7177
}
7278
}
7379
}

lib/node_modules/@stdlib/fs/write-file/bin/cli

+20-23
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
* limitations under the License.
1919
*/
2020

21-
2221
'use strict';
2322

2423
// MODULES //
@@ -31,23 +30,6 @@ var cwd = require( '@stdlib/process/cwd' );
3130
var writeFile = require( './../lib' );
3231

3332

34-
// FUNCTIONS //
35-
36-
/**
37-
* Callback invoked upon writing a file.
38-
*
39-
* @private
40-
* @param {Error} [error] - error object
41-
* @returns {void}
42-
*/
43-
function onWrite( error ) {
44-
if ( error ) {
45-
process.exitCode = 1;
46-
return console.error( 'Error: %s', error.message ); // eslint-disable-line no-console
47-
}
48-
}
49-
50-
5133
// MAIN //
5234

5335
/**
@@ -72,12 +54,15 @@ function main() {
7254
})
7355
});
7456

57+
// Get any provided command-line options:
58+
flags = cli.flags();
59+
if ( flags.help || flags.version ) {
60+
return;
61+
}
62+
7563
// Get any provided command-line arguments:
7664
args = cli.args();
7765

78-
// Get any provided command-line flags:
79-
flags = cli.flags();
80-
8166
opts = {};
8267
if ( flags.encoding ) {
8368
opts.encoding = flags.encoding;
@@ -103,11 +88,23 @@ function main() {
10388
*/
10489
function onRead( error, data ) {
10590
if ( error ) {
106-
process.exitCode = 1;
107-
return console.error( 'Error: %s', error.message ); // eslint-disable-line no-console
91+
return cli.error( error );
10892
}
10993
writeFile( fpath, data, opts, onWrite );
11094
}
95+
96+
/**
97+
* Callback invoked upon writing a file.
98+
*
99+
* @private
100+
* @param {Error} [error] - error object
101+
* @returns {void}
102+
*/
103+
function onWrite( error ) {
104+
if ( error ) {
105+
return cli.error( error );
106+
}
107+
}
111108
}
112109

113110
main();

0 commit comments

Comments
 (0)