Skip to content
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

Cue commands that generate json/other files should have the option --compact #2477

Open
rudifa opened this issue Jul 9, 2023 · 7 comments
Open
Labels
FeatureRequest New feature or request

Comments

@rudifa
Copy link
Contributor

rudifa commented Jul 9, 2023

Is your feature request related to a problem? Please describe.
While commands def, export and eval generate indented json files, in some applications the compact (minified) json is desirable, for space and time economy.

Describe the solution you'd like
cue export data.cue --compact should produce a compact data.json file.

Describe alternatives you've considered
I can reformat the indented json file with jq or any similar tool, but getting it on demand from cue would be more efficient.

Additional context
The only mention of compact in CUE issues and in pull requests I could find is in PR #1549, suggested as a possibility by @mpvl and commented on favourably by @rogpeppe and @felixge.

While the desired effect of --compact is obvious for json, for other formats discussed in #1549 probably should be 'minify', i.e. remove anything that conveys no machine readable information.

@rudifa rudifa added FeatureRequest New feature or request Triage Requires triage/attention labels Jul 9, 2023
@myitcv myitcv removed the Triage Requires triage/attention label Jul 10, 2023
@myitcv
Copy link
Member

myitcv commented Jul 10, 2023

Modulo naming, this seems a reasonable feature request.

@jpluscplusm
Copy link
Collaborator

Please include the comma-delimited, white-space-removed (comments removed?) single-line form of CUE in the set of output formats being targeted by this Issue's putative option.

@myitcv myitcv changed the title Cue commands that generate json files should have the option --compact Cue commands that generate json/other files should have the option --compact Jul 14, 2023
@myitcv
Copy link
Member

myitcv commented Jul 14, 2023

Updated the title to reflect that this request is not specific to JSON, but could/should be applied to all output formats.

@rudifa
Copy link
Contributor Author

rudifa commented Jul 15, 2023

#2492 was more a convergent request than a duplicate of this one.

I limited my request to JSON because it corresponds to the immediate need of my project, but

  • it is not an urgent need: it is easy to post process the indented JSON
  • it would be more efficient if compacting could be done on demand in the serialization step

Questions, for my CUEducation:

  • is "comma-delimited, white-space-removed single-line form of CUE" format currently supported on input to CUE?
  • if yes, where is this format specified?
  • or would this be a display-only format?

@jpluscplusm
Copy link
Collaborator

jpluscplusm commented Jul 15, 2023

[snip]

Questions, for my CUEducation:

Unofficial answers from an enCUEsiast, rather than someone who definitively knows what they're taking about:

  • is "comma-delimited, white-space-removed single-line form of CUE" format currently supported on input to CUE?

Yes. If you use the rudimentary tr|tr|sed I outlined in the duplicate Issue (after having manually removed any CUE comments), you /should/ find it transforms simple enough CUE texts into acceptable single-line equivalents. As noted, it doesn't handle multi-line strings or comments, and I'm not even sure that comments /can/ be handled in a single-line form.

I'm confident there are also other corner cases it fails to deal with.

  • if yes, where is this format specified?

This section of the language guide might be useful: https://cuelang.org/docs/references/spec/#lexical-elements

I didn't use that, however - it was more trial and error :-)

  • or would this be a display-only format?

I'm not sure a display-only form of the language exists. Personally, I'm only interested in a form that can be used as input.

@rudifa
Copy link
Contributor Author

rudifa commented Jul 15, 2023

@jpluscplusm Thank you for the guidance, I'll follow it up (not as my first priority).

By 'display-only format' I meant something like this, for use in testing

    assert.Equal(`{·str: "hello world"·num: 42·flt: 3.14·"k8s.io/annotation": "secure-me"·list: ["a", "b", "c", 1, 2, 3]·obj: {·foo: "bar"·L: ["a", "b", "c", 1, 2, 3]·}·}`,
		myfmt.CompactCueVal(cueval), "-")

@yujunz
Copy link

yujunz commented Nov 7, 2023

Is there anyone already working on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
FeatureRequest New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants