redocly-cli icon indicating copy to clipboard operation
redocly-cli copied to clipboard

Support for env var parameters

Open jwilner opened this issue 1 year ago • 2 comments
trafficstars

Is your feature request related to a problem? Please describe.

Currently, the project doesn't support environment variables for parameterizing the CLI's behavior. This can result in frustrating conditional construction of CLI invocations littered through more complex toolchains. For instance, our linting code has to call:

if [[ -n "${GITHUB_ACTIONS-}" ]]; then
    npx @redocly/cli lint --format=github-actions 
else
   npx @redocly/cli lint
fi

Describe the solution you'd like

A standard pattern would be to support prefixed environment variables directly mapping to your CLI args. The CLI arg library this project uses supports this very feature. Thus, a minimal change to your application -- e.g. .env("REDOCLY_CLI") -- would permit easier cross-cutting parameterization for clients like REDOCLY_CLI_OUTPUT_FORMAT=github-actions.

I'm happy to open up this PR if it seems like something the project would welcome.

jwilner avatar Nov 07 '24 14:11 jwilner

This seems like a good idea. What do you think @tatomyr ?

adamaltman avatar Nov 19 '24 23:11 adamaltman

Sorry, I somehow missed this. Yes, it's a good idea. However, for supporting options with names containing dashes (like lint-config), we might need to turn on the camel-case-expansion option.

tatomyr avatar Jan 08 '25 15:01 tatomyr