Skip to content

Align CLI behavior with go-jsonnet#1068

Open
He-Pin wants to merge 4 commits into
databricks:masterfrom
He-Pin:codex/go-jsonnet-cli-compat
Open

Align CLI behavior with go-jsonnet#1068
He-Pin wants to merge 4 commits into
databricks:masterfrom
He-Pin:codex/go-jsonnet-cli-compat

Conversation

@He-Pin

@He-Pin He-Pin commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Motivation

sjsonnet CLI should be a go-jsonnet-compatible superset for applicable CLI behavior, while making remaining intentional differences explicit.

Modification

  • Allow --help / --version without an input file and keep control flags inactive when they are option values or after --.
  • Align -J priority with go-jsonnet right-most-wins behavior while keeping JSONNET_PATH lower priority.
  • Align YAML stream, output-file newline, create-output-dirs, max-trace, and -- terminator behavior with go-jsonnet where applicable.
  • Harden short-option normalization for attached values such as -Jdir and -n4.
  • Keep sjsonnet's existing CLI tail-call optimization behavior and test it explicitly.

Result

Case go-jsonnet v0.22.0 jrsonnet 0.5.0-pre99 sjsonnet before sjsonnet after
--version without input prints version prints version parser error prints Sjsonnet 0.7.1-SNAPSHOT
--help without input prints help prints help parser error prints help without parser noise
-- --version with file named --version evaluates file evaluates file parser error evaluates file
-J a -J b duplicate import path imports from b imports from b imports from a imports from b
--yaml-stream -e '[{a:1},{b:2}]' JSON document stream with --- YAML document stream old stream formatting JSON document stream with ---
--max-stack 2 non-tail recursion stack error stack error stack error stack error
--max-stack 2 tail recursion stack error stack error returns 0 via TCO returns 0 via TCO
-Jdir / -n4 attached values not supported for -Jdir supported broken short cluster parsing supported as sjsonnet robustness

References

  • Local behavior checks against go-jsonnet v0.22.0 and jrsonnet 0.5.0-pre99.

@He-Pin He-Pin marked this pull request as draft June 29, 2026 03:17
@He-Pin He-Pin force-pushed the codex/go-jsonnet-cli-compat branch from 4664627 to e335c1e Compare June 29, 2026 03:39
Motivation:
Close CLI compatibility gaps with go-jsonnet, including option parsing, output behavior, environment/JPATH handling, and stack accounting semantics.

Modification:
Update CLI config and main flow, add JVM CLI compatibility tests, and keep tail-call trampolines from consuming the user-facing maxStack budget while preserving maxStack failures for non-tail recursion.

Result:
The PR branch is represented as one cohesive commit and the JVM CI failure is fixed by aligning tests with the intended tail-recursive stack behavior.

References:
databricks#1068
@He-Pin He-Pin force-pushed the codex/go-jsonnet-cli-compat branch from c2ac117 to d82f180 Compare June 29, 2026 05:45
@He-Pin He-Pin marked this pull request as ready for review June 29, 2026 17:57
He-Pin added 3 commits June 30, 2026 12:08
Motivation:
The assembly smoke test expected tail-recursive CLI evaluation to hit the stack limit, but sjsonnet preserves TCO for tail calls and MainTests already assert that behavior.

Modification:
Use a non-tail recursive expression for the max-stack failure smoke check, and add an explicit tail-recursive success smoke check.

Result:
The smoke test now verifies both the stack-limit error path and the existing tail-call optimization path without contradicting runtime behavior.
Motivation:
Short option normalization expanded every character in a cluster before checking whether any option consumed a value. Attached values such as -Jdir or -n4 were therefore split into unrelated flags.

Modification:
Stop cluster expansion when a value-taking short option is encountered, treating the rest of the token as that option value. Add CLI tests for attached -J and -n values while preserving flag-only clusters such as -eS.

Result:
The CLI handles attached short option values predictably and the JVM test suite, formatting check, and assembly smoke pass.
Motivation:
The stack trace cropping split could produce only an ellipsis for --max-trace 1 and no tail frame for --max-trace 2.

Modification:
Keep at least one visible head frame for limit 1 and at least one tail frame for larger cropped traces. Add CLI regression coverage for --max-trace 1 and 2.

Result:
Small max-trace limits keep useful stack evidence, and checkFormat, JVM tests, and assembly smoke pass.
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.

1 participant