Skip to content

Commit 28013fa

Browse files
committed
Update CLI
1 parent 0107715 commit 28013fa

File tree

4 files changed

+163
-77
lines changed

4 files changed

+163
-77
lines changed

lib/node_modules/@stdlib/utils/detect-weakmap-support/bin/cli

+19-77
Original file line numberDiff line numberDiff line change
@@ -3,88 +3,30 @@
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 resolve = require( 'path' ).resolve;
7+
var readFileSync = require( '@stdlib/fs/read-file' ).sync;
8+
var CLI = require( '@stdlib/tools/cli' );
129
var detect = require( './../lib' );
1310

1411

15-
// FUNCTIONS //
16-
17-
/**
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.
40-
*
41-
* @private
42-
* @example
43-
* help();
44-
* // => '...'
45-
*/
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 );
54-
}
55-
} // end FUNCTION help()
12+
// MAIN //
5613

5714
/**
58-
* Prints the package version.
15+
* Main execution sequence.
5916
*
6017
* @private
61-
* @example
62-
* version();
63-
* // => '#.#.#'
6418
*/
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;
75-
76-
77-
// MAIN //
78-
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-
console.log( detect() );
19+
function main() {
20+
// Create a command-line interface:
21+
var cli = new CLI({ // eslint-disable-line no-unused-vars
22+
'pkg': require( './../package.json' ),
23+
'options': require( './../etc/cli_opts.json' ),
24+
'help': readFileSync( resolve( __dirname, '..', 'docs', 'usage.txt' ), {
25+
'encoding': 'utf8'
26+
})
27+
});
28+
29+
console.log( detect() ); // eslint-disable-line no-console
30+
} // end FUNCTION main()
31+
32+
main();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
'use strict';
2+
3+
// MODULES //
4+
5+
var resolve = require( 'path' ).resolve;
6+
var exec = require( 'child_process' ).exec;
7+
var tape = require( 'tape' );
8+
var IS_BROWSER = require( '@stdlib/assert/is-browser' );
9+
var IS_WINDOWS = require( '@stdlib/assert/is-windows' );
10+
var readFileSync = require( '@stdlib/fs/read-file' ).sync;
11+
12+
13+
// VARIABLES //
14+
15+
var fpath = resolve( __dirname, '..', 'bin', 'cli' );
16+
var opts = {
17+
'skip': IS_BROWSER || IS_WINDOWS
18+
};
19+
20+
21+
// FIXTURES //
22+
23+
var PKG_VERSION = require( './../package.json' ).version;
24+
25+
26+
// TESTS //
27+
28+
tape( 'command-line interface', function test( t ) {
29+
t.ok( true, __filename );
30+
t.end();
31+
});
32+
33+
tape( 'when invoked with a `--help` flag, the command-line interface prints the help text to `stderr`', opts, function test( t ) {
34+
var expected;
35+
var cmd;
36+
37+
expected = readFileSync( resolve( __dirname, '..', 'docs', 'usage.txt' ), {
38+
'encoding': 'utf8'
39+
});
40+
cmd = [
41+
process.execPath,
42+
fpath,
43+
'--help'
44+
];
45+
46+
exec( cmd.join( ' ' ), done );
47+
48+
function done( error, stdout, stderr ) {
49+
if ( error ) {
50+
t.fail( error.message );
51+
} else {
52+
t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' );
53+
t.strictEqual( stderr.toString(), expected+'\n', 'expected value' );
54+
}
55+
t.end();
56+
}
57+
});
58+
59+
tape( 'when invoked with a `-h` flag, the command-line interface prints the help text to `stderr`', opts, function test( t ) {
60+
var expected;
61+
var cmd;
62+
63+
expected = readFileSync( resolve( __dirname, '..', 'docs', 'usage.txt' ), {
64+
'encoding': 'utf8'
65+
});
66+
cmd = [
67+
process.execPath,
68+
fpath,
69+
'-h'
70+
];
71+
72+
exec( cmd.join( ' ' ), done );
73+
74+
function done( error, stdout, stderr ) {
75+
if ( error ) {
76+
t.fail( error.message );
77+
} else {
78+
t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' );
79+
t.strictEqual( stderr.toString(), expected+'\n', 'expected value' );
80+
}
81+
t.end();
82+
}
83+
});
84+
85+
tape( 'when invoked with a `--version` flag, the command-line interface prints the version to `stderr`', opts, function test( t ) {
86+
var cmd = [
87+
process.execPath,
88+
fpath,
89+
'--version'
90+
];
91+
92+
exec( cmd.join( ' ' ), done );
93+
94+
function done( error, stdout, stderr ) {
95+
if ( error ) {
96+
t.fail( error.message );
97+
} else {
98+
t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' );
99+
t.strictEqual( stderr.toString(), PKG_VERSION+'\n', 'expected value' );
100+
}
101+
t.end();
102+
}
103+
});
104+
105+
tape( 'when invoked with a `-V` flag, the command-line interface prints the version to `stderr`', opts, function test( t ) {
106+
var cmd = [
107+
process.execPath,
108+
fpath,
109+
'-V'
110+
];
111+
112+
exec( cmd.join( ' ' ), done );
113+
114+
function done( error, stdout, stderr ) {
115+
if ( error ) {
116+
t.fail( error.message );
117+
} else {
118+
t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' );
119+
t.strictEqual( stderr.toString(), PKG_VERSION+'\n', 'expected value' );
120+
}
121+
t.end();
122+
}
123+
});
124+
125+
tape( 'the command-line interface prints either `true` or `false` to `stdout` indicating whether an environment provides native `WeakMap` support', opts, function test( t ) {
126+
var cmd = [
127+
process.execPath,
128+
fpath
129+
];
130+
131+
exec( cmd.join( ' ' ), done );
132+
133+
function done( error, stdout, stderr ) {
134+
var str;
135+
if ( error ) {
136+
t.fail( error.message );
137+
} else {
138+
str = stdout.toString();
139+
t.strictEqual( str === 'true\n' || str === 'false\n', true, 'prints either `true` or `false` to `stdout`' );
140+
t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' );
141+
}
142+
t.end();
143+
}
144+
});

0 commit comments

Comments
 (0)