-
Notifications
You must be signed in to change notification settings - Fork 995
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
help()
using yargs.default
#2010
Comments
@SheetJSDev that's quite weird, I notice it cropping up as far back as |
This comment has been minimized.
This comment has been minimized.
I tracked down some symptoms with some wild tracing, but not sure about the fix yet. When var yargs_1 = require("yargs");
var args = yargs_1.default(process.argv.slice(2)).help().default({ 'ddd': 'DDD' }).argv;
Note the |
@bcoe FWIW some form of this bug actually goes all the way back to 4.0.0 (7 years ago !) $ npm i --save yargs@4.0.0
$ cat t.js
var yargs_1 = require("yargs");
var args = yargs_1.default(process.argv.slice(2)).help().argv;
$ node t.js --help
Options:
-0 [default: "--help"]
--help Show help [boolean]
$ cat tt.js
var yargs_1 = require("yargs");
var args = yargs_1(process.argv.slice(2)).help().argv;
$ node tt.js --help
Options:
--help Show help [boolean] |
Another datapoint is the issue occurs with the singleton, but not with a fresh instance. (Also some differences in the above comment.) Edit: and
|
The help option is not special, the same issue occurs with an ordinary option too:
|
Oh, just worked out why my reproduction is behaving oddly. When calling Is that also what the generated TypeScript calls? Might just be a conflict with the Enough for tonight, to be resumed... |
Ok, got to the bottom of the failure mode. I was able to reproduce the issue from a TypeScript file by commenting out the With
The example TypeScript configuration in the Yargs documentation does have I need to do some more reading to see if the Yargs implementation can play better with TypeScript here, or whether updating the Yargs documentation to be more explicit about working patterns is the best approach. |
Note that TS's module system is fundamentally broken if you don't have |
Some related issues:
(Thanks for comment @ljharb ) |
Yargs has a complicated history of usage, and four entry points used here, and TypeScript allows various approaches, and // import * as yargs from "yargs";
// import yargs from "yargs";
// import yargs = require("yargs");
import yargs from 'yargs/yargs';
console.log(yargs(process.argv.slice(2)).help().default('aaa', 'AAA').argv);
Edit: updated July 2023 with much improved compatibility. I was not previously using Edit: found further problems in #483 when |
My current understanding is this is not a bug as such. Three thoughts for improvements:
|
I looked into throwing an error if Yup. There is an apparently undocumented behaviour that can pass an array of keys and have them set to same value. Can't detect the broken TypeScript import without breaking something else. So current plan is update the documentation and hope people trip over the import problem less! Example of using array:
% node array.js --help
Options:
--help Show help [boolean]
--version Show version number [boolean]
-a [default: 3]
-b [default: 3] |
The original typescript code looked like:
The generated JS code looks like
Save that to
t.js
and runnode t.js --help
:It adds 2 hyphens irrespective of the number of hyphens and also wraps:
Subsequent arguments are written with two dashes:
The same behavior occurs if you set the script to executable and prepend the shebang:
The text was updated successfully, but these errors were encountered: