Giter VIP home page Giter VIP logo

Comments (11)

xyy94813 avatar xyy94813 commented on July 18, 2024 3

What's the advantage?
Emmm... You can ignore the way I suggest to use it.

But refactor by command the code will be easy to read.

When i use dotenv-cli without <My command>,

Throw a Error: [ERR_INVALID_ARG_TYPE]: The "file" argument must be of type string. Received type undefined

It took me a long time to find out the cause of the problem.

spawn(argv._[0], argv._.slice(1), { stdio: 'inherit' })

Because argv._[0] is undefined

In addition, I hope that my use of the scene can bring a little inspiration

The following is my usage scenario:


Normally, i just need the default .env.
So, i just need configure script like this in package.json

{
"scripts": {
    "dev": "dotenv next dev"
  },
}

it is work well too

{
"scripts": {
    "dev": "dotenv -- next dev"
  },
}

But, some time i need to debug in diff deploy environment.
And i do not want to configure many script in package.json, because they are not commonly used.

I choice the first config, so that i can do something like this:

yarn run dev -e .env.debug.local

Woo~, everything in my control


The command next dev support a arg --port to control dev server port

if i use the arg --port base script dev

yarn run dev -e .env.debug.local -- --port  3001
// it is seem work well, actually not

Because yarn will ignore the first --

warning From Yarn 1.0 onwards, scripts don't require "--" for options to be forwarded. In a future version, any explicit "--" will be forwarded as-is to the scripts.
// what you excute command is
// yarn run dev -e .env.debug.local --port  3001
yarn run dev -e .env.debug.local -- -- --port 3001
npm run dev -e .env.debug.local -- -- --port 3001
// work well, but too many `--`, and It's hard to understand what command did

from dotenv-cli.

lagren avatar lagren commented on July 18, 2024 1

I had a similar problem and it was fixed by adding --.

Thanks for the tip, @entropitor

from dotenv-cli.

entropitor avatar entropitor commented on July 18, 2024

Does dotenv mvn exec:java -- -Dexec.args="-g -f" work?

from dotenv-cli.

jaydenseric avatar jaydenseric commented on July 18, 2024

So how do you run dotenv node --experimental-modules server.mjs?

It just hangs without doing anything...

from dotenv-cli.

entropitor avatar entropitor commented on July 18, 2024

I'm guessing dotenv node -- --experimental-modules server.mjs.

Basically any command line flag you want to parse to a the subprocess you're creating should be behind the -- as dotenv-cli will ignore everything after there

from dotenv-cli.

xyy94813 avatar xyy94813 commented on July 18, 2024

Maybe we can refactor by use commander

It is simple to write a command tool.

Then We can use dotenv-cli like this

dotenv -e .env1 .env2 .env3 command <My command with args>

from dotenv-cli.

entropitor avatar entropitor commented on July 18, 2024

@xyy94813 What's the advantage? You can already do this, as describe in this issue and by the README: https://github.com/entropitor/dotenv-cli#flags-to-the-underlying-command

You just need to add --

dotenv -e .env1 .env2 .env3 -- command <My command with args>

from dotenv-cli.

xyy94813 avatar xyy94813 commented on July 18, 2024

dotenv MyCommand -e XXX not equal dotenv -- MyCommand -e XXX

It is a bit counterintuitive

from dotenv-cli.

entropitor avatar entropitor commented on July 18, 2024

The -- is very common see e.g. https://unix.stackexchange.com/questions/11376/what-does-double-dash-mean-also-known-as-bare-double-dash

And your use-case is exactly an example of one why we want such a thing. Without it, the -e .env.debug.local flag would be passed to the next dev executable, NOT to dotenv

Feel free to fork the repo and publish your own version btw, but I believe it's better if we do use the --

from dotenv-cli.

galleonpt avatar galleonpt commented on July 18, 2024

I have a similar problem and tried with "--" but it still doesn't work.
My example:

I have the following script in my package.json

"test": "dotenv -e .env.test && docker compose up -d && yarn prisma migrate deploy && jest -i"

When I run yarn test it doesn't work.

How should I write my command? @entropitor

from dotenv-cli.

entropitor avatar entropitor commented on July 18, 2024
dotenv -e .env.test -- bash -c "docker compose up -d && yarn prisma migrate deploy && jest -i"

If it doesn't, I don't know by hard. This is basic shell priority, this CLI doesn't do anything special

from dotenv-cli.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.