cue icon indicating copy to clipboard operation
cue copied to clipboard

Ability to set working directory

Open btrepp opened this issue 1 year ago • 1 comments

Is your feature request related to a problem? Please describe. I am calling cue from a makefile, but the cue files might be in a subdirectory. Usually with a makefile I have paths to input and output files, but I might be in the root of a project.

Cue seems to always think it's going to be invoked either explicitly with files, or via being in the working directory. Usually tools that work that way, have commands to specify the working directory, eg git -C. With cue it appears I will need to CD that directory, then manipulate all the file paths to be absolute or from that directory.

Note: with 1 file, it's fine, you can call cue export path/to/my.cue, but as I am now trying to break this into multiple files, it appears I either need to track all the files that are in the folder, or to change the working directory

Describe the solution you'd like An extra flag --working-dir much like https://git-scm.com/docs/git#Documentation/git.txt--Cltpathgt

Describe alternatives you've considered There's probably the ability to rewrite into modules, or understand the package system, though the package system is currently quite confusing to me. Alternatively I can cd first and rewrite paths of output files in make.

There could be other ways too, but it's just seems to be bits of magic with working-directories that make it all a bit harder to understand, maybe if cue didn't automatically load the current dir, and you needed to provide a 'directory' context instead of files, that would unify behaviour, eg you always need to pass 'what' you want it to load, files or a directory, not files, unless nothing, then load CWD, and or have to change to CWD then load CWD.

Additional context Add any other context or screenshots about the feature request here.

btrepp avatar Oct 13 '24 00:10 btrepp

Just as a quick drive-by comment: the info in cue help inputs is your friend, here.

To process (i.e. export/eval/etc) a specific CUE package, you can use either an absolute or relative "import path" as a positional parameter to the relevant cue command, instead of changing into the directory containing that package.

For instance, cue export ./foo/bar is the same as cd foo/bar; cue export. And if there's more than one package in that directory, a colon-separated suffix can be used to specify the package you're interested in:

cue export ./foo/bar:wibble # export package "wibble"

jpluscplusm avatar Oct 17 '24 17:10 jpluscplusm

Ah yes, @jpluscplusm thanks for that!. You are correct.

Its helpful to know that it does work that way, as the error messages can be interesting, the leading '.' is very important, if not it gets treated as an in-built and the error message is a bit confusing, which made me end up thinking it didn't work that way.

btrepp avatar Dec 14 '24 04:12 btrepp

Mhmm revisiting this. I am not sure if this is the case like other tools.

import failed: imports are unavailable because there is no cue.mod/module.cue file

This technique seems to only work if you are already in the of the cue project, and wanting to run in the context of a folder. If you are outside of the cue folder entirely, eg say the root of a mono-repo, you get the above error.

For now the trick seems to be 'cd-ing' into the cue command before hand, but its not exactly as clean in build tools

btrepp avatar Apr 14 '25 13:04 btrepp

@btrepp - I think what you/we probably want here is https://github.com/cue-lang/cue/issues/1918

myitcv avatar Apr 16 '25 19:04 myitcv