Multi-line item value function calls #154
Replies: 1 comment 2 replies
-
Option 1 looks the most normal to me but I don't know how much you value supporting legacy parsers. The other options that show repeating keys or functions would get a little verbose for me with my setup since I'd be defining env vars for 7 different environments (local, tests, docker, dev, impl, preprod, and prod). Supporting a default case also runs into the same issue as Option 3 where you'd need to match against something special that would not conflict. Perhaps it would be a special syntax on top of option 1 where instead of commas you'd use a
Another nice-to-have would be to define multiple cases to a single value somehow, either by something like falling through or matching in array of keys
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Currently config item values (other than multi-line strings) must be on a single line. For complex nested function calls, this obviously makes things hard to read. We'd like a way of splitting up long complex function calls across multiple lines to make things clearer.
Some context on why it works this way currently:
Aside from making the parser simpler, the idea here is to maintain some backwards compatibility with most .env/bash parsers. Of course many things wouldn't work if not using varlock (or another env-spec compatible parser), but at least parsing would not fail. There is a discussion to be had around whether that goal is worthwhile at all - so please chime in on that front...
Env-based switch example
Currently we encourage users to split env-specific config into multiple files and use
@envFlag
, but there are cases where a user may want to use a single file, more like DMNO. We do currently provide aremap
helper function, but it has limitations, and one can imagine a better helper function for this purpose.problems with remap
key=val
syntax to try to make things clearer but...regex()
Consider a situation where we want to switch a value based on
APP_ENV
, with production, preview, and development have different values. We'll introduce a new functionswitchBy
which should take in an input (usually just another item), then look through a list of possible cases, returning a new value if a match is found. The values themselves could be long function calls, especially if fetching data from a remote source, so right away that points to breaking things up on multiple lines. The matching cases could also be simple static values, or regular expressions. We could also provide a special default case, or rely on wrapping the entire thing withfallback()
.Option 1 - disregard backwards compat
Simplest seeming option (to end users) is to stop caring about backwards compatibility for legacy env parsers. Of course there are many syntax options (arrays, key value objects, etc), but here is a simple one where we rely on item order and providing pairs of key/value.
✅ it's fairly intuitive
❌ totally breaks legacy parsers
❌ adds quite a bit of complexity to the parser and language syntax
❌ there is now the possibility of comments within the middle of a function call?
Option 2 - repeating keys, coupled functions + merging definitions
Instead we could repeat the key, and do some merging of the definitions.
✅ fairly clear
❌ bit verbose
❌ new coupled function calls, need to merge together definitions which could get a bit weird
Option 3 - use special key
A slight variation of above, where we dont repeat the key, but instead use a special key
✅ bit less verbose
✅ more clear that something special is happening instead of defining a thing twice
❌ need to find a key that is unlikely to never conflict with any real env var
Option 4 - use comments/decorators
There are variations where we could use decorators/comments to mark specific lines as matching certain cases. The main downside here is that at least currently, the decorator value are not the same thing as the item values, so doing things like regexes would be a totally new and custom system. Maybe not the end of the world though?
❌ custom implementation for regex matching, etc
❌ I dont love the matching criteria being after the value
Very open to ideas and opinions here!
Beta Was this translation helpful? Give feedback.
All reactions