You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
the execution of BAR='a non-empty string' <program> will currently never populate Args.Bar.Pos.
This behavior (or... lack thereof, technically) occurs whether the env: tag is defined on Args.Bar, PosArg.Pos, or both.
I recommend changing the approach of how environment variables are processed:
1.) First, before go-flags' tags are processed, run it through e.g. https://pkg.go.dev/github.com/caarlos0/env/v11. While this adds a dependency, it has the benefit of offloading env var processing logic from this project (and ensures env vars are handed per *NIX conventions, see below) (the particular library I linked to is, I think, the most popular and well-maintained env-to-struct library for Golang). This should then also handle nested structs (such as positional args).
2.) Then perform normal go-flags' tag processing/reflection.
This not only would resolve this bug, but it is also backwards-compatible (the library I linked uses the same tag name) and would respect *NIX conventions for priority; first CLI flags/args/switches, then env vars, then configuration files. (This priority ordering arose as a convention because it allows for runtime-contextual options (CLI invocation) to apply over session-contextual options (env vars), both of which can override system-contextual/default options (config files).)
The text was updated successfully, but these errors were encountered:
Given:
the execution of
BAR='a non-empty string' <program>
will currently never populate Args.Bar.Pos.This behavior (or... lack thereof, technically) occurs whether the
env:
tag is defined on Args.Bar, PosArg.Pos, or both.I recommend changing the approach of how environment variables are processed:
1.) First, before go-flags' tags are processed, run it through e.g. https://pkg.go.dev/github.com/caarlos0/env/v11. While this adds a dependency, it has the benefit of offloading env var processing logic from this project (and ensures env vars are handed per *NIX conventions, see below) (the particular library I linked to is, I think, the most popular and well-maintained env-to-struct library for Golang). This should then also handle nested structs (such as positional args).
2.) Then perform normal go-flags' tag processing/reflection.
This not only would resolve this bug, but it is also backwards-compatible (the library I linked uses the same tag name) and would respect *NIX conventions for priority; first CLI flags/args/switches, then env vars, then configuration files. (This priority ordering arose as a convention because it allows for runtime-contextual options (CLI invocation) to apply over session-contextual options (env vars), both of which can override system-contextual/default options (config files).)
The text was updated successfully, but these errors were encountered: