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

Idea to include global.argv / minimist? #46

Closed
smeijer opened this issue May 10, 2021 · 9 comments
Closed

Idea to include global.argv / minimist? #46

smeijer opened this issue May 10, 2021 · 9 comments

Comments

@smeijer
Copy link

smeijer commented May 10, 2021

This library is a timesaver! What do you think of the idea to also add passed-in arguments to the global, using something like minimist?

The change:

global.argv = require('minimist')(process.argv.slice(2));

Run script:

$ zx sync.js --username smeijer

Usage:

let username = argv.username || await question('What is your username? ')
@smeijer smeijer changed the title Idea to include minimist? Idea to include global.argv / minimist? May 10, 2021
@rauschma
Copy link

Another argument parsing library to consider (I personally prefer it over minimist): https://github.com/vercel/arg

@antonmedv
Copy link
Collaborator

The problem with it what there are too many alternatives, and everybody wants a different one.

  • yargs ~57M/week
  • minimist ~41M/week
  • arg ~7M/week
  • meow ~15M/week
  • countless others ~100M/week

@smeijer
Copy link
Author

smeijer commented May 11, 2021

I was thinking about limiting the integration to expose the arguments under global.argv, in the most basic form. Arguments would be exposed as strings when a value was provided (zx script.js --username smeijer), or booleans when not (zx script.js -xyz). We could consider detecting numbers, and parsing those, but that already makes it tricky.

Whenever the user needs more (like support for --help, or type coercion), they can install their library of choice.

For this project, I think the best option would be the simplest/smallest library.

@mainrs
Copy link

mainrs commented May 11, 2021

We could consider detecting numbers, and parsing those, but that already makes it tricky.

No need for that. If a script uses the API it already knows if an argument should be a number. Stuff like that should be handled by the script writer. A simple string/boolean case should be enough.

Maybe instead of going for popularity of a parsing package one could argue that the smallest one with the fastest loading time might be the best to choose. Just another way to look at the discussion.

@smeijer
Copy link
Author

smeijer commented May 11, 2021

My thoughts exactly

@ethanmick
Copy link

Using zx for the first time and really enjoying it. This use case just came up as I wanted to add a little more configuration for other users who may use it. A simple way to get flagged arguments would be very nice. Maybe some inspiration can be taken from the Go flag package; simple, and if people still need more power than can install another one.

@brandonpittman
Copy link

Another argument parsing library to consider (I personally prefer it over minimist): vercel/arg

arg is definitely the closest to the metal and inline with zx's vision.

@smeijer
Copy link
Author

smeijer commented May 25, 2021

The difference I see between minimist and arg, is that minimist doesn't require any options/setup to be useful. While arg needs initialization.

As arg requires setup, one might as well just add the import statement as well.

@antonmedv
Copy link
Collaborator

Done! Minimist in v2.

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

No branches or pull requests

6 participants