sindresorhus / cpy-cli

Copy files
MIT License
344 stars 33 forks source link

Add `nonull` to CLI param #7

Closed alexander-akait closed 7 years ago

schnittstabil commented 8 years ago

For the sake of completeness, the default behavior was introduced by:

Therefore, nonull is already set to true at cli.js#L33.

That said, I think the current behavior is reasonable for a CLI application. @evilebottnawi Can you give us some context, why this feature is useful for you?

alexander-akait commented 8 years ago

@schnittstabil i make standard npm scripts for fast build sites and sometimes any directories may empty and i got error, try to use cash-true unstable and give error on some window :cry:

schnittstabil commented 8 years ago

Ah, of course cpy-cli … || true doesn't help much, because cpy may stop copying on first error.

@sindresorhus IMO a --null option would be helpful in some cases, I would like to do implement it, if you agree:

--null  If a pattern matches no paths, the pattern is ignored, rather than
        used literally as path

About the naming: bash calls this option nullglob, thus --null-glob also sounds appropriate.

alexander-akait commented 8 years ago

/cc @sindresorhus

sindresorhus commented 8 years ago

@schnittstabil Is there any way we can solve this without an option? If not, we at least need a clearer name than --null.

schnittstabil commented 8 years ago

Is there any way we can solve this without an option?

I'm afraid not, nonull: true is reasonable for almost all interactive CLI sessions.

However, in npm scripts it's sometimes fine, that the patterns doesn't match any paths, but e.g. permission errors should still stop the build, thus cpy … || true or similar doesn't help.

Naming alternatives:

sindresorhus commented 8 years ago

@schnittstabil It's just slighty annoying as this sets a precedence that every tool that supports globbing would have to implement such option. You know I don't like options.

--ignore-no-match sounds good.

schnittstabil commented 8 years ago

It's just slighty annoying as this sets a precedence that every tool that supports globbing…

We might do it by means of globby and environment variables:

   "copy": "GLOBBY_IGNORE_NO_MATCH=yes cpy …"

I don't know, whether that's such a good idea though.

alexander-akait commented 8 years ago

@schnittstabil With https://www.npmjs.com/package/cross-env should work fine on all platforms, later tests this solution

schnittstabil commented 8 years ago

@evilebottnawi globby doesn't support it (yet) - this was just an idea…

alexander-akait commented 8 years ago

@schnittstabil :disappointed: