-
Notifications
You must be signed in to change notification settings - Fork 100
[Feat] Determine the format automatically for input files on the CLI #2267
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
Merged
+116
−17
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Hmm, the snapshot test failure happens on the CI but not on my machine... |
🎉 All dependencies have been resolved ! |
0b9a1d0
to
70a12d5
Compare
70a12d5
to
571237a
Compare
nbacquey
approved these changes
May 27, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Otherwise lgtm
cli/tests/snapshot/snapshots/snapshot__export_stdout_mixed_formats.ncl.snap
Outdated
Show resolved
Hide resolved
57b3464
to
43e41a9
Compare
86cf728
to
555a32c
Compare
|
Branch | feat/multi-format-cli |
Testbed | ubuntu-latest |
Click to view all benchmark results
Benchmark | Latency | microseconds (µs) |
---|---|---|
fibonacci 10 | 📈 view plot 🚷 view threshold | 290.48 µs |
foldl arrays 50 | 📈 view plot 🚷 view threshold | 400.92 µs |
foldl arrays 500 | 📈 view plot 🚷 view threshold | 3,748.50 µs |
foldr strings 50 | 📈 view plot 🚷 view threshold | 4,567.30 µs |
foldr strings 500 | 📈 view plot 🚷 view threshold | 46,200.00 µs |
generate normal 250 | 📈 view plot 🚷 view threshold | 42,371.00 µs |
generate normal 50 | 📈 view plot 🚷 view threshold | 1,626.40 µs |
generate normal unchecked 1000 | 📈 view plot 🚷 view threshold | 2,125.20 µs |
generate normal unchecked 200 | 📈 view plot 🚷 view threshold | 444.61 µs |
pidigits 100 | 📈 view plot 🚷 view threshold | 2,305.30 µs |
pipe normal 20 | 📈 view plot 🚷 view threshold | 687.40 µs |
pipe normal 200 | 📈 view plot 🚷 view threshold | 5,916.00 µs |
product 30 | 📈 view plot 🚷 view threshold | 255.41 µs |
scalar 10 | 📈 view plot 🚷 view threshold | 595.30 µs |
sum 30 | 📈 view plot 🚷 view threshold | 258.78 µs |
jneem
approved these changes
Jun 2, 2025
0095d96
to
896b23a
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Depends on #2266
Supporting multiple input formats on the CLI
Motivation
When importing a file, Nickel determines the format automatically by looking at the file's extension. This is not true on the CLI though, which could be useful: for example, one could use Nickel as a merging engine for JSON without actually needing to migrate anything to Nickel:
nickel base.json ext.json foo.json
. In conjunction with #2266, supporting other formats on the CLI could also allow validating non-Nickel config in a lightweight and non-invasive way:nickel eval config.json --apply-contract validation/*.ncl
.Content
Instead of always determining the input format to be
Nickel
for files coming from the CLI, this PR uses the same logic as for imports, looking at the file's extension.Shortcomings
One current shortcoming is that, as opposed to imports, there is no way to override the format selection logic. However, we've lived with that for a long time with imports - the explicit format syntax is relatively recent -, and the motivation for imports is a bit different. The explicit format syntax for imports is more about specifying the format explicitly when Nickel doesn't recognize the extension, say with
foo.data
that should be text, rather than overriding an import namedfoo.json
to be understood as TOML instead. The latter would be a very strange use-case.Thus, this PR should be a strict improvement over the previous situation, which would consider
foo.json
as a Nickel input, and shouldn't require any work-around, although it could be extended in some way to specify the format explicitly.