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

Automatic .env file support #526

Open
ilog2000 opened this issue Mar 30, 2022 · 7 comments
Open

Automatic .env file support #526

ilog2000 opened this issue Mar 30, 2022 · 7 comments

Comments

@ilog2000
Copy link

It would be good to have automatic .env file detection and parsing, while variables-file option and environment variables should work as overrides.

@fabricereix
Copy link
Collaborator

Hi @ilog2000 ,
Hurl can use environment variables HURL_xxx from the system.
https://hurl.dev/docs/man-page.html#environment

Therefore you can just put these variables in your .env file and source it before running Hurl.
for example

source .env || true

@ilog2000
Copy link
Author

Hi @fabricereix , I understand what you are saying. I tried hurl on Windows, where source command does not exist, and I need to make some BAT file tricks to do the same. So, I know it is possible, but not convenient. Main goal of this ticket is to make hurl use as short as

hurl my-script.hurl

without long typing or batch files.

@lepapareil
Copy link
Collaborator

lepapareil commented Apr 1, 2022

Hi @ilog2000

Software magic/automatic *.env file detection/parsing always depends on user's specific needs and developers patterns (there is no real IT cross-platform specification) so there are many ways to achieve what you expect:

  • env file location has to be in: current directory ? User home directory ? Hurl exec directory ? Hurl file directory ? Etc ...
  • env file name has to be: same as hurl file base name ? Prefixed with "hurl" ? Both ? Etc ...
  • env file extension has to be: *.env ? *.properties ? *.conf ? Etc ...

As hurl philosophy is to keep the code simple, high-performing and explicit, we plan to allow the creation of variables directly inside hurl files, we can also consider using multiple --variable-file like we did with --variable.

This would allow you to manage all cases:

# one file, one var
hurl --test --variable myvar=1 test_dir/test.hurl
hurl --test test_dir/test.hurl (with myvar=1 inside hurl file)

# one file, common vars and one var override
hurl --test --variable-file common_dir/common.env --variable myvar=1 test_dir/test.hurl
hurl --test --variable-file common_dir/common.env test_dir/test.hurl (with myvar=1 inside hurl file)

# one file, common vars and multiple vars overrides
hurl --test --variable-file common_dir/common.env --variable-file test_dir/test.hurl test_dir/test.hurl

# multiple files, common vars and one or multiple vars overrides according to the file
hurl --test --variable-file common_dir/common.env test_dir/*.hurl (with myvar=1 and yourvar=1 only setted inside needed files)

@ilog2000
Copy link
Author

ilog2000 commented Apr 4, 2022

Hi @lepapareil

Sorry, my bad, I had to explain the concept of .env (no claim it was my idea). It is no "magic", just a very simple convention consisting of 4 rules:

  1. File is always named .env (not .conf, not my.cfg, not anything else)
  2. Only file in the current directory where scripts located is picked up (no user home dir, no global configuration)
  3. File contents are lines in name=value format
  4. Those name=value lines are set as environment variables overriding global environment variables, so they add "environmental" context to the particular directory.

Practically any programming language has an implementation of this convention:

Stars in corresponding repositories will reflect the popularity of this idea. On the other hand I know at least one very popular piece of software which does not process .env automatically, but only via command line option - this is Docker.

I am not trying to push hurl authors to accept this my suggestion, the decision is definitely up to them. I am just saying I personally find the idea of automatic .env file processing very convenient.

@lepapareil
Copy link
Collaborator

Hi @ilog2000,

I definitively agree with you about the ease of use of .env files for final users and that simplifying vars overrides for each executed hurl.file is a real need 👍🏻.

I just wanted to point out that there is not specs and even though it looks simple and is developed in several languages, it is not implemented the same way (except the first rule):

  • some override vars by default, others not
  • some are compatible with multiline var value, others not
  • some source only from root dir, others are recursive by default
  • etc ...

Sorry if i may have misspoken, i am not at all trying to push hurl authors not to accept your suggestion 😄, i just wanted to debate the pros and cons.

@luolong
Copy link

luolong commented Dec 1, 2022

There's a sort of spec: https://hexdocs.pm/dotenvy/dotenv-file-format.html

@jcamiel
Copy link
Collaborator

jcamiel commented Dec 21, 2023

See also #290

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

5 participants