-
Notifications
You must be signed in to change notification settings - Fork 298
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cmd/cue: support --package flag when output is CUE
When running def and export (the latter when --out cue is set) it is sometimes desirable to ensure that the resulting CUE belongs to a package. This situation arises by default when non-CUE input is consumed by cmd/cue, but can also occur when (for example) cue def produces self-contained output. The --package (-p) flag is currently used to define the package name implied by non-CUE inputs. It seems safe and appropriate to reuse this flag for the manifestation of CUE at least. Fixes #2240 Signed-off-by: Paul Jolly <[email protected]> Change-Id: Iacce853ff36526fa70b3e92e9b6f9297187568e8 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1177546 TryBot-Result: CUEcueckoo <[email protected]> Reviewed-by: Daniel Martí <[email protected]> Unity-Result: CUE porcuepine <[email protected]>
- Loading branch information
Showing
3 changed files
with
92 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Ensure that cue def with a --package flag outputs CUE that belongs to a | ||
# package. | ||
|
||
# Regular cue def | ||
exec cue def -p blah x.cue | ||
cmp stdout orig.golden | ||
|
||
# Self-contained | ||
exec cue def -p blah -e x x.cue | ||
cmp stdout self_contained.golden | ||
|
||
|
||
-- x.cue -- | ||
#Def: int | ||
x: #Def & 5 | ||
|
||
-- orig.golden -- | ||
package blah | ||
|
||
#Def: int | ||
x: #Def & { | ||
5 | ||
} | ||
-- self_contained.golden -- | ||
package blah | ||
|
||
DEF.#x & { | ||
5 | ||
} | ||
|
||
//cue:path: #Def | ||
let DEF = { | ||
#x: int | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# Verify that -p works when exporting as CUE. | ||
|
||
# Case 1: only non-CUE inputs | ||
exec cue export --out cue -p blah x.json y.json | ||
cmp stdout stdout.golden | ||
|
||
# Case 2: CUE input which does not declare a package (with JSON) | ||
exec cue export --out cue -p blah nopkg.cue x.json y.json | ||
cmp stdout stdout.golden | ||
|
||
# Case 3: CUE input which does declare same package (with JSON) | ||
exec cue export --out cue -p blah pkg.cue x.json y.json | ||
cmp stdout stdout.golden | ||
|
||
# Case 4: CUE input with mis-matched package (with JSON) | ||
# | ||
# TODO: in the future we could allow "repackaging" via --force which would | ||
# cause this export to succeed with the package clause 'blah' in the result. | ||
! exec cue export --out cue -p blah diffpkg.cue x.json y.json | ||
cmp stderr stderr.golden | ||
|
||
-- x.json -- | ||
{ | ||
"x": 5 | ||
} | ||
-- y.json -- | ||
{ | ||
"y": 4 | ||
} | ||
-- nopkg.cue -- | ||
x: 5 | ||
y: 4 | ||
-- pkg.cue -- | ||
package blah | ||
|
||
x: 5 | ||
y: 4 | ||
-- diffpkg.cue -- | ||
package other | ||
|
||
x: 5 | ||
y: 4 | ||
-- stdout.golden -- | ||
package blah | ||
|
||
x: 5 | ||
y: 4 | ||
-- stderr.golden -- | ||
"package" flag clashes with existing package name (blah vs other) |
This file contains 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