Skip to content
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

Default to parsing command-line arguments for yargs factory too #2399

Open
shadowspawn opened this issue Apr 12, 2024 · 0 comments
Open

Default to parsing command-line arguments for yargs factory too #2399

shadowspawn opened this issue Apr 12, 2024 · 0 comments

Comments

@shadowspawn
Copy link
Member

shadowspawn commented Apr 12, 2024

The old singleton pattern defaulted to the most common case of parsing the command-line arguments:

const yargs = require('yargs');
const argv = yargs.parse();

The new factory pattern is currently a bit clunky by comparison.

const yargs = require('yargs/yargs');
const {hideBin} = require('yargs/helpers');
const argv = yargs(hideBin(process.argv)).parse();

If we default to the command-line arguments we get back to close to the singleton ergonomics. Single import. Simple creation.

const yargs = require('yargs/yargs');
const argv = yargs().parse();

It seems reasonably easy and potentially non-breaking. Am I missing something?

(I wonder if retaining the default behaviour got left out or was more difficult early on with the big refactors to move to the factory pattern and multi-platform node/deno/browser.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant