Skip to content

feat(cli): resolve $(...) expressions in string flag values#235

Draft
ruflin wants to merge 1 commit into
elastic:mainfrom
ruflin:feat/cli-flag-resolvers
Draft

feat(cli): resolve $(...) expressions in string flag values#235
ruflin wants to merge 1 commit into
elastic:mainfrom
ruflin:feat/cli-flag-resolvers

Conversation

@ruflin
Copy link
Copy Markdown
Contributor

@ruflin ruflin commented Apr 27, 2026

Extends the existing config-file resolver registry (file, env, cmd, keychain, etc.) so it also applies to string-typed CLI flag values.

This lets users load a file directly into any string flag, e.g.

elastic stack kb workflows post-workflows-workflow --yaml '$(file:./workflow.yaml)'

Before to load a workflow directly from a file I had to run:

elastic stack kb workflows post-workflows-workflow --yaml "$(cat workflow.yaml)"

This is mostly convenience. Lets discuss also potential other options. Ideally this works the same across all files that can be loaded.

Extends the existing config-file resolver registry (file, env, cmd,
keychain, etc.) so it also applies to string-typed CLI flag values.

This lets users load a file directly into any string flag, e.g.

  elastic stack kb workflows post-workflows-workflow \
    --yaml '$(file:./workflow.yaml)'

instead of having to inline shell-escaped contents. Works on both
hand-written OptionDefinitions and schema-derived string args, runs
before Zod validation, and surfaces missing files with a clear error
that names the offending flag. The fast path stays synchronous when
the value contains no expression so existing parser-based tests are
unaffected.
@github-actions
Copy link
Copy Markdown

MegaLinter analysis: Success

Descriptor Linter Files Fixed Errors Warnings Elapsed time
✅ COPYPASTE jscpd yes no no 5.09s
✅ REPOSITORY gitleaks yes no no 64.25s
✅ REPOSITORY git_diff yes no no 0.09s
✅ REPOSITORY secretlint yes no no 2.7s
✅ REPOSITORY trivy yes no no 19.19s
✅ TYPESCRIPT eslint 2 0 0 5.31s

See detailed reports in MegaLinter artifacts
Set VALIDATE_ALL_CODEBASE: true in mega-linter.yml to validate all sources, not only the diff

MegaLinter is graciously provided by OX Security
Show us your support by starring ⭐ the repository

@ruflin
Copy link
Copy Markdown
Contributor Author

ruflin commented Apr 27, 2026

Instead of having the file: approach, using elastic stack kb workflows post-workflows-workflow --yaml-file workflow.yaml feels more intuitive. Can someone comment if that fits the cli architecture?

@JoshMock
Copy link
Copy Markdown
Member

Instead of having the file: approach, using elastic stack kb workflows post-workflows-workflow --yaml-file workflow.yaml feels more intuitive. Can someone comment if that fits the cli architecture?

I like this approach more than the resolver approach. However, there is already a global --input-file flag as well as global support for receiving JSON via stdin. I would propose modifying those features to optionally support YAML input on a per-command basis rather than building a custom solution for one command.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants