nodeca / argparse

CLI arguments parser for node.js. JS port of python's argparse module.
Other
491 stars 73 forks source link

REPL throwing error on ArgumentParser Instantiation. #138

Closed M3TIOR closed 4 years ago

M3TIOR commented 5 years ago

Discovery

I'm the kind of programmer who like to test code on the go before I trust my intuition. As such I spend a lot of time using REPL interfaces to play around in code. Upon using the library on the July 21, 2019; I encountered the following stacktrace while trying to instantiate an ArgumentParser from the REPL:

TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type undefined
    at validateString (internal/validators.js:107:11)
    at Object.basename (path.js:1149:5)
    at new ArgumentParser (/home/m3tior/Git/argparse/lib/argument_parser.js:71:40)
    at repl:4:17

Patch

After playing around in your source to dig up the problem, I found the issue was a null accommodation for supporting NodeJS's REPL. It's fully possible it was unaccounted for because programmers / scripters unlike myself usually don't test for it. I added the following fix in my local copy that seemed to resolve the issue; although as of yet I have not added complex enough test cases to prove the REPL is fully supported:

// @71:40
// default program name; empty by default when scripting interactively.
options.prog = (options.prog || Path.basename(process.argv[1] || ''));

Future Goals

At the time of writing this, I've actually already written and added the test case to your library that proves this problem is reproducible. I'll be following up shortly with the commit that fixes the issue and adds my test case for your convenience.

rlidwka commented 4 years ago

fixed in 2.0