cue-lang / docs-and-content

A place to discuss, plan, and track documentation on cuelang.org
6 stars 1 forks source link

concept guide: basic file / package handling for newcomers #51

Open jpluscplusm opened 9 months ago

jpluscplusm commented 9 months ago

In https://cuelang.slack.com/archives/C012UU8B72M/p1704734939104439, a new CUE user was confused by the error message found packages "apackage" (a.cue) and bpackage (b.cue) in "C:\\Users\\Downloads".

We don't have a basic starter doc explaining how CUE translates package addresses to files on disk (including the CLI-only . prefix).

Original thread Sri [28 days ago](https://cuelang.slack.com/archives/C012UU8B72M/p1704734939104439) I am new to cue and have multiple packages in folder and I tried this. I would appreciate it if you could point out where I might be missing something. `a.cue` has ``` package apackage testa: { abc:"def" } ``` and `b.cue` has ``` package bpackage testb: { ghi:"jkl" } ``` and `c.cue has ``` package apackage let cvar = testa p: cvar ` but I got the following error when I run - found packages "apackage" (a.cue) and bpackage (b.cue) in "C:\\Users\\Downloads" (edited) 5 replies Mike Semcheski [28 days ago](https://cuelang.slack.com/archives/C012UU8B72M/p1704735947446779?thread_ts=1704734939.104439&cid=C012UU8B72M) I think the general pattern is one package per directory :gratitude-thank-you: 1 myitcv [27 days ago](https://cuelang.slack.com/archives/C012UU8B72M/p1704778904669919?thread_ts=1704734939.104439&cid=C012UU8B72M) The pattern is indeed generally speaking one package per directory, but that's not a strict requirement myitcv [27 days ago](https://cuelang.slack.com/archives/C012UU8B72M/p1704779265954879?thread_ts=1704734939.104439&cid=C012UU8B72M) ``` exec cue export .:apackage cmp stdout stdout.golden -- a.cue -- package apackage testa: { abc: "def" } -- b.cue -- package bpackage testb: { ghi: "jkl" } -- c.cue -- package apackage let cvar = testa p: cvar -- stdout.golden -- { "testa": { "abc": "def" }, "p": { "abc": "def" } } ``` myitcv [27 days ago](https://cuelang.slack.com/archives/C012UU8B72M/p1704779286515879?thread_ts=1704734939.104439&cid=C012UU8B72M) Notice the use of `.` to select the current directory, and then :apackage to select a specific package in that directory myitcv [27 days ago](https://cuelang.slack.com/archives/C012UU8B72M/p1704779294576799?thread_ts=1704734939.104439&cid=C012UU8B72M) This applies to any CUE input/import path