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

cuelang.org: cue eval -p documentation is incorrect #1136

Open
PierreR opened this issue Jul 24, 2021 · 3 comments
Open

cuelang.org: cue eval -p documentation is incorrect #1136

PierreR opened this issue Jul 24, 2021 · 3 comments

Comments

@PierreR
Copy link

PierreR commented Jul 24, 2021

What version of CUE are you using (cue version)?

$ cue version
cue version 0.4.0 linux/amd64

Does this issue reproduce with the latest release?

yes

What did you do?

Given 2 files foo.cue and bar.cue

src/foo.cue

package foo

foo: "hello"

src/bar.cue

package bar

bar: "world"

cue eval -p foo ./src 
found packages "foo" (foo.cue) and "bar" (bar.cue) in ".../src"

What did you expect to see?

I expect the error message to be printed when using cue eval ./src and to disappear when adding the -p option as in the documentation at https://cuelang.org/docs/concepts/packages/#files-belonging-to-a-package

What did you see instead?

Same behavior with or without -p

@myitcv
Copy link
Member

myitcv commented Jul 26, 2021

Hmm, this appears to be a bug in the docs. Because, to my knowledge, -p has never been used for this purpose. -p is used for specifying a package where one cannot be inferred from context, e.g. where OpenAPI is consumed as input, and the user wants to specify a package as part of the output.

In the case you link to from the docs, the package selection happens as part of the package pattern specified on the command line:

# One package in the current directory
exec cue eval

# Two packages in the x directory
! exec cue eval ./x

# Choose package x
exec cue eval ./x:x

# Choose package y
exec cue eval ./x:y

-- a.cue --
package a

import "mod.com/x"

x
-- cue.mod/module.cue --
module: "mod.com"
-- x/x.cue --
package x

x: 5
-- x/y.cue --
package y

y: 5

Gives:

# One package in the current directory (0.048s)
> exec cue eval
[stdout]
x: 5
# Two packages in the x directory (0.033s)
> ! exec cue eval ./x
[stderr]
found packages "x" (x.cue) and y (y.cue) in "$WORK/x"
[exit status 1]
# Choose package x (0.041s)
> exec cue eval ./x:x
[stdout]
x: 5
# Choose package y (0.039s)
> exec cue eval ./x:y
[stdout]
y: 5
PASS

So I will repurpose this issue for fixing up those docs.

But I've also raised #1138, because I think the behaviour of imports and cmd/cue package resolution should be consistent with respect to ambiguous package selection.

@myitcv myitcv added Documentation NeedsFix and removed NeedsInvestigation Triage Requires triage/attention labels Jul 26, 2021
@myitcv myitcv changed the title cue eval -p option has no effect cuelang.org: cue eval -p documentation is incorrect Jul 26, 2021
@myitcv myitcv added the S label Jul 29, 2021
@vikstrous2
Copy link

I ran into this today too. This is very confusing since even the docs got it wrong.

@myitcv myitcv removed the S label Oct 26, 2021
@adrienbrault
Copy link

Was able to figure out how to export a specific package thanks to this issue.

$ cue export
found packages "config" (config.cue) and hello (hello.cue) in "..."

$ cue export :config
{
    "foo": "bar"
}

$ cue export :hello
{
    "hello": "world"
}

@myitcv myitcv added the zGarden label Jun 15, 2023
@mvdan mvdan removed the zGarden label Feb 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants