Skip to content

Add a way to apply a contract to a file from the command line #2216

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
yannham opened this issue Apr 9, 2025 · 0 comments
Open

Add a way to apply a contract to a file from the command line #2216

yannham opened this issue Apr 9, 2025 · 0 comments

Comments

@yannham
Copy link
Member

yannham commented Apr 9, 2025

Is your feature request related to a problem? Please describe.
One possible, and minimally invasive usage of Nickel, is to use it to apply schemas to existing configuration that isn't necessarily written in Nickel (e.g. YAML). While the CLI currently supports passing files that aren't Nickel, such as nickel export foo.json bar.json baz.ncl, this only implements merging, which isn't exactly equivalent to contract application, even for record contracts (for example merging won't complain about extra fields).

Describe the solution you'd like
Add a --contract schema.ncl argument to evaluation commands, so that one can apply a contract to a file directly from the CLI without having to modify said files (when it's even possible), such as nickel eval foo.json --contract myschema.ncl or nickel export data.ncl --contract contract.ncl. We could support many contracts arguments, that would just be applied in order.

Describe alternatives you've considered
A current work-around is to do something like nickel eval <<< '(import "data.json") | (import "contract.ncl")' which is heavier and might have escaping subtleties. It also doesn't really scale to several contracts (it's still doable, but worse).

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

No branches or pull requests

1 participant