Skip to content
This repository has been archived by the owner on Nov 18, 2021. It is now read-only.

cmd/cue: allow exporting one expression only #240

Closed
nmrshll opened this issue Dec 21, 2019 · 4 comments
Closed

cmd/cue: allow exporting one expression only #240

nmrshll opened this issue Dec 21, 2019 · 4 comments
Labels
FeatureRequest New feature or request roadmap/cli Specific tag for roadmap issue #337

Comments

@nmrshll
Copy link

nmrshll commented Dec 21, 2019

With cue eval, we get the option -e to evaluate one expression (path) only.
It would be useful to get the same option for the export command.

Use case

When applying k8s configs to a cluster, I often want to apply specific deployments at a time.
I use the export command to get the output in a format kubernetes understands (json for now).
But I need to be able to export an expression/path of my configs at a time.
So I end up using both eval to get one expression only, then export to transform to json.

cue eval -e deployments.dep1 manyDeps.cue > .cache/dep1.cue
cue export .cache/dep1.cue

But I wish to be able to do that in one command (no temp file needed).

Potential solutions (not working for now)

  1. Add a -e flag to the export command, which would work the same way as the one for the eval command:
    cue export -e deployments.dep1 manyDeps.cue

  2. Allow cue export to work with more files than just files named *.cue
    This could allow using file descriptors as input (and process substitution):
    cue export <(cue eval -e deployments.dep1 manyDeps.cue)

  3. Still work with files with different names than *.cue, but the user needs to be explicit about it.
    For instance using -f as a flag to select the input file:
    cue export -f deps.notcue
    and adapted to my case:
    cue export -f <(cue eval -e deployments.dep1 manyDeps.cue)

  4. Allow input from stdin instead of files.
    Some tools use the -f - syntax:
    commandThatProducesCue | cue export -f -
    and adapted to my case:
    cue eval -e deployments.dep1 manyDeps.cue | cue export -f -


I would favour number 1, as it seems closest to what is already there in the tool (adds less to learn).
Any other opinions ? About this problem (is it worth solving) ? And any of these or other possible solutions ?
Or any strong reasons to not do any of this ?

@mpvl mpvl added roadmap/cli Specific tag for roadmap issue #337 FeatureRequest New feature or request labels Dec 22, 2019
@mpvl
Copy link
Contributor

mpvl commented Dec 22, 2019

There is a design slated for v0.0.16 where calling cue without command allows any supported file type to be input and evaluated and output. The -m flag would allow selecting files to "merge" with the other specified files. The -e flag would work. In case of ambiguity, filenames can be qualified. For instance, foo.json:openapi tells cue to interpret foo.json as OpenAPI instead of regular JSON. Similarly, -o foo.cue:data tells cue to output only data. This effectively unifies eval and export into a single, more flexible command.

@nmrshll
Copy link
Author

nmrshll commented Jan 6, 2020

Sounds like good ways to go ! And nice to know I can already specify how to interpret a file with another way than its name only. I'll give that feature a try, see if it works well with autogenerated file-descriptor names.
And I'll keep in tune for the next version !
Thanks

@mpvl mpvl closed this as completed in dcffaef Feb 19, 2020
@nmrshll
Copy link
Author

nmrshll commented Feb 20, 2020

Excellent ! Thank you @mpvl !

@cueckoo
Copy link

cueckoo commented Jul 3, 2021

This issue has been migrated to cue-lang/cue#240.

For more details about CUE's migration to a new home, please see cue-lang/cue#1078.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FeatureRequest New feature or request roadmap/cli Specific tag for roadmap issue #337
Projects
None yet
Development

No branches or pull requests

3 participants