just icon indicating copy to clipboard operation
just copied to clipboard

1748-dotenv-files

Open sbeckeriv opened this issue 1 year ago • 6 comments

Dearest Reviewer,

I was looking at the parser and the format for a list of things [] was already support for shells. I reused that concept to make an ordered list of strings.

This now works

set dotenv-files := [".env1", ".env2"]

As does the command line

just --dotenv-files .env1 --dotenv-files .env2 echo

The new setting is applied last. It does not change how the other two settings currently work.

I do have a problem I cant get this to work

ENV := "prod"
set dotenv-files := [".env.{{ENV}}", ".env"]

it the {{ENV}} never turns in to prod. I am using parse_string_literal.

the issue https://github.com/casey/just/issues/1748 asked about fallback justfiles. I have not used them and I would take any advice on what to change for that as well.

Any advice would be appreciated

Thanks Becker

sbeckeriv avatar May 02 '24 07:05 sbeckeriv

Not very related to the PR, but to my knowledge, the ".env.{{ENV}}" is working as expected since interpolation only works in recipes. The alternative would be to write something like:

ENV := "prod"
set dotenv-files := [".env."+ENV, ".env"]

omar25h avatar May 12 '24 20:05 omar25h

Does this need to be a separate setting? I strikes me that set dotenv-file could be extended to accept either a single item, or an array of items, with a single item being equivalent to an array containing that single item. Additionally, the --dotenv-filenname could be changed to accept multiple items.

casey avatar May 19 '24 04:05 casey

Does this need to be a separate setting? I strikes me that set dotenv-file could be extended to accept either a single item, or an array of items, with a single item being equivalent to an array containing that single item. Additionally, the --dotenv-filenname could be changed to accept multiple items.

I made the new setting in response to the comment here https://github.com/casey/just/issues/1748#issuecomment-2081443912.

Originally I had setting it more then once here https://github.com/casey/just/pull/1940.

I could redo dotenv-file take a string or list with the current dotenv-file and accept the command line multiple times. Kind of munging the two PRs together.

The parse_ordered_list i wrote only works with static strings. I have not figured out how to get an expression working ie: ".env."+ENV. I would need some pointers or an example on how i can handle that correctly.

sbeckeriv avatar May 20 '24 17:05 sbeckeriv

I made the new setting in response to the comment here #1748 (comment).

Originally I had setting it more then once here #1940.

I think having a single setting that takes an array is a better idea. Otherwise, the two settings conflict.

The parse_ordered_list i wrote only works with static strings. I have not figured out how to get an expression working ie: ".env."+ENV. I would need some pointers or an example on how i can handle that correctly.

It will have to take a static string. dotenv file settings are applied before anything in the justfile is evaluated, so it can't use variables. I did merge #2055 recently, which adds a new kind of string literal which can contain environment variables, so those can be used.

casey avatar May 20 '24 21:05 casey

Also, this needs tests, including tests which cover how different ways dotenv files can be specified interact with each other.

casey avatar May 20 '24 21:05 casey

Converting to a draft so I can keep track of what's ready to go. Feel free to undraft when it's ready!

casey avatar May 25 '24 08:05 casey