hashicorp / hashicorp/go-envparse

Feature request: Permissive parse mode

Open
#13 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
54
Forks
11
Avg merge
7h 57m
Merged PRs (30d)
1

Description

This library handles strict env files wonderfully. It's nice to be able to work with such a limited scope, so I understand if this request is not within the project scope. I'm happy to maintain my fork for my own purposes, but perhaps others would benefit from a permissive parse mode as well.

I also recognize that this project bills itself as an "environment variable parser". So what I'm proposing is also not within that scope. So, again, I understand if this request is not within scope.

With that said, I think the project's description undersells what this library does. I use it as a general-purpose key-value file parser. I give it files to parse, and it gives me key-value pairs in return. Typically, these files are standard env files of the form

```
FOO=bar
BAZ=biz
```

Sometims they're a little more complex, because I think it's important to document environment variables.

```
# FOO configures the jabberwocky. See https://jabberwockydocs.com/foo for details.
FOO=bar
BAZ=biz
```

I love it when `.env` files have comments, because it's not always clear where their values come from, or what values are valid. Comments clear that up.

But what about files that contain a bunch of key-value pairs, comments, and _other stuff_. A good example of these are `.envrc` files:

```bash
#!/bin/bash

export FOO=bar
export BAZ=biz

# Say hello when users enter this directory
function hello {
echo "Hello world"
}

hello
```

Here we have a bash script containing variables and other functionality. I'd love to be able to extract the key-value pairs from this file, while ignoring the rest of it.

A permissive parse mode allows `FOO` and `BAR` to be extracted, while paying no attention to all the bash-specific lines in the file.

I have a proof-of-concept forked at https://github.com/acaloiaro/go-envparse.

Supporting a permissive mode changes very little about how files are parsed: https://github.com/acaloiaro/go-envparse/commit/f2ef76301b481973a6fbe927b9259d5a22cca251

If this is of any interest, I'm happy to open a PR. If not, please feel free to close this issue without dicussion. Cheers!

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.