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

Make possible to provide the env file pathes in the Makefile.toml #306

Closed
olvyko opened this issue Nov 4, 2019 · 5 comments
Closed

Make possible to provide the env file pathes in the Makefile.toml #306

olvyko opened this issue Nov 4, 2019 · 5 comments
Assignees
Milestone

Comments

@olvyko
Copy link

olvyko commented Nov 4, 2019

Features Description
Make possible to provide the env file path (--env-file) in the Makefile.toml.

Describe the solution you'd like
Now, when you use --env-file, you need to call cargo make like this:

cargo make --env-file=./env/dev1.env dev

but it would be cool if you could provide the env file pathes in the Makefile.toml,

Code Sample
(for example, but can be implemented differently)

[tasks.dev]
description = "Big dev task ..."
command = "cargo"
args = ["run"]

[tasks.test]
description = "Big test task ..."
command = "cargo"
args = ["test"]

[env-files]
dev = ["./env/dev1.env", "./env/dev2.env"]
test = "./env/test.env"

then just run cargo make dev or cargo make test and all env-files will be attached automatically.

@sagiegurari
Copy link
Owner

nice, few questions:

  • test = "./env/test.env" - what is test? is that like a profile name, so only for test profile we will load the file? because per your example its the task name which seems a bit strange.
  • env-files will be loaded before the env block (same as cli env files defined). hope it makes sense.
  • how about this instead:
env-files = [
 "./myfile.env",
 "${HOME}/anotherfile.env",
 { file = "dev1.env", profile = "dev" },
 { file = "dev2.env", profile = "dev" },
 { file = "test.env", profile = "test" },
]

few things about this example:

  • env files is a list
  • we support env expansion
  • we can load files per profile is relevant, not per task
  • env-files is global key meaning loaded when cargo-make boots and task key meaning loaded when a task is invoked (this allows you to define it per task as per original request)

would this fit your needs?

@enfipy
Copy link

enfipy commented Nov 5, 2019

Your solution with profiles in parentheses is good but maybe it would be better to make it like [env]?

For example following code:

[tasks.dev]
description = "Big dev task ..."
command = "cargo"
args = ["run"]
[tasks.dev.env]
DEV1_ENV = false
DEV2_ENV = true

will work same as:

[tasks.dev]
description = "Big dev task ..."
command = "cargo"
args = ["run"]
env-files = [
  "./dev1.env",
  "${HOME}/dev2.env",
]

with corresponding env files.

And if somebody will want to add global env file something like this:

[env]
DEV3_ENV = "yes"
env-files = [
  "./dev1.env",
  "${HOME}/dev2.env",
]

[tasks.dev]
description = "Big dev task ..."
command = "cargo"
args = ["run"]

@sagiegurari
Copy link
Owner

just that i'm clear on your solution, basically you are saying to expand the capabilities of env block and have in it a new keyword env-files.
right now env keywords are the actual env keys or profile names that hold a sub env block (although you can override it by doing someprofile=somevalue instead of a block in your makefile).

if i understood correctly, the problem here

[env]
env-files = [
  "./dev1.env",
  "${HOME}/dev2.env",
]

is that you are blocking env-files from being an env var key without the ability to override that behaviour.
meaning, cargo-make will never enable you to define an env var with key env-files.
that's why i was ok with a new env type block as suggested called [env-files] which lives in parallel to [env]

i'm open for suggestions on how to make it simpler.

as for the task example you gave:

[tasks.dev]
env-files = [
  "./dev1.env",
  "${HOME}/dev2.env",
]

it is what i meant in my original post:

and task key meaning loaded when a task is invoked (this allows you to define it per task as per original request)

so i think we are fine with that.
but if you look, here in your example, the attribute is env-files and not env so there is no conflict.

@sagiegurari
Copy link
Owner

@olvyko and @enfipy this feature is now available in the 0.24.0 development branch.
you can try it out and provide feedback before it goes to official release.
The documentation is here: https://github.com/sagiegurari/cargo-make/tree/0.24.0#usage-env-file

@sagiegurari
Copy link
Owner

this is no published officially in 0.24.0 release.

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

3 participants