Skip to content

Feature request: Permissive parse mode #13

@acaloiaro

Description

@acaloiaro

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:

#!/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: acaloiaro@f2ef763

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions