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

Args not passed to other process #8

Closed
OlivierKamers opened this issue May 28, 2017 · 11 comments
Closed

Args not passed to other process #8

OlivierKamers opened this issue May 28, 2017 · 11 comments

Comments

@OlivierKamers
Copy link

For example: dotenv mvn exec:java -Dexec.args="-g -f" does not pass those -g -f args into the Java method, whilst mvn exec:java -Dexec.args="-g -f" works in this case.

@entropitor
Copy link
Owner

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

@lagren
Copy link

lagren commented Sep 26, 2017

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

Thanks for the tip, @entropitor

entropitor added a commit that referenced this issue Sep 26, 2017
@jaydenseric
Copy link

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

It just hangs without doing anything...

@entropitor
Copy link
Owner

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

@xyy94813
Copy link

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>

@entropitor
Copy link
Owner

entropitor commented Mar 27, 2019

@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>

@xyy94813
Copy link

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

@xyy94813
Copy link

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

It is a bit counterintuitive

@entropitor
Copy link
Owner

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 --

@galleonpt
Copy link

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

@entropitor
Copy link
Owner

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

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