now should be usable/testable in browser...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2020-06-29 20:21:25 +03:00
parent cf29608c6a
commit 88e189142d

20
argv.js
View File

@ -374,7 +374,8 @@ object.Constructor('Parser', {
// If this is set to false Parser will not call process.exit(..) on // If this is set to false Parser will not call process.exit(..) on
// error... // error...
handleErrorExit: function(arg){ handleErrorExit: function(arg){
process.exit(1) }, typeof(process) != 'unhandled'
&& process.exit(1) },
// post parsing callbacks... // post parsing callbacks...
// //
@ -402,7 +403,9 @@ object.Constructor('Parser', {
var nested = false var nested = false
var rest = this.rest = var rest = this.rest =
argv == null ? argv == null ?
process.argv (typeof(process) != 'unhandled' ?
process.argv
: [])
: argv : argv
argv = rest.slice() argv = rest.slice()
main = main main = main
@ -432,7 +435,7 @@ object.Constructor('Parser', {
value = value value = value
|| ((handler.arg && !opt_pattern.test(rest[0])) ? || ((handler.arg && !opt_pattern.test(rest[0])) ?
rest.shift() rest.shift()
: handler.env ? : (typeof(process) != 'unhandled' && handler.env) ?
process.env[handler.env] process.env[handler.env]
: undefined) : undefined)
// value conversion... // value conversion...
@ -486,11 +489,12 @@ object.Constructor('Parser', {
// unhandled... // unhandled...
unhandled.push(arg) } unhandled.push(arg) }
// call env handlers that were not explicitly called yet... // call env handlers that were not explicitly called yet...
this.envOptions() typeof(process) != 'unhandled'
.forEach(function([k, a, d, handler]){ && this.envOptions()
env.has(handler) .forEach(function([k, a, d, handler]){
|| (handler.env in process.env env.has(handler)
&& runHandler(handler, a, null, rest)) }) || (handler.env in process.env
&& runHandler(handler, a, null, rest)) })
// post handlers... // post handlers...
root_value = root_value && this.handleArgumentValue ? root_value = root_value && this.handleArgumentValue ?
this.handleArgumentValue(this, root_value) this.handleArgumentValue(this, root_value)