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

Using multiple justfiles / default include user-just file #1025

Closed
kaihowl opened this issue Nov 13, 2021 · 10 comments
Closed

Using multiple justfiles / default include user-just file #1025

kaihowl opened this issue Nov 13, 2021 · 10 comments

Comments

@kaihowl
Copy link

kaihowl commented Nov 13, 2021

Hi,

I was thinking of the following use case: Let's consider I have project specific justfiles that invoke the right build / test commands for the project in the directory in which they are placed. But there are a few cross-project commands that are useful to have in every project, e.g., applying clang-format. These won't change between different projects.

Instead of copying them into every justfile, I'd much rather put them in a user-level justfile. From the README.adoc I thought I could just place them in the ~/.user.justfile and have them available next to all other recipes from the local justfile. This is not the case as far as I can tell from experimentation. Next I tried supplying multiple -f parameters. This is also not allowed.

I understand that including multiple justfiles makes conflict resolution of recipe names necessary. It also invites other corner cases and might be overall undesirable. I tried searching for past discussions on the issue tracker but was not very lucky to find relevant ones.

Therefore, I decided to create this issue to get an understanding of what is already possible and what can be considered future improvements, for which you are willing to accept PRs.

Thank you so much for such a well-maintained project. :)

@casey
Copy link
Owner

casey commented Nov 13, 2021

Thank you for the kind words! Thank you for using just 🙇‍♂️

I think this probably depends on adding some kind of module system, which is tracked in #383. You'd want to have a module system, import the user-level justfile in your justfile, and then call recipes from the user-level justfile.

@kaihowl
Copy link
Author

kaihowl commented Nov 24, 2021

I understand. That ticket probably makes more sense in the long run.

Since I admittedly only skimmed #383, please let me know if the following is addressed there already and I have to give the ticket a more detailed read:

Would allowing multiple -f parameters with the semantic of concatenating all recipes be acceptable? In case of recipe conflicts, the invocation would outright fail and not continue.

If this is not an acceptable idea for reasons that I overlooked, please feel free to close this ticket in favor of #383.

@casey
Copy link
Owner

casey commented Nov 24, 2021

It's not that it should be closed in favor of #383, it's that it depends on #383. The best way to implement this feature is to first add a module system, and then use that module system to combine the justfile in the invocation directory with the justfile in .user.justfile.

@jpbochi
Copy link
Contributor

jpbochi commented Aug 4, 2022

FWIW, the need for this feature is reduced by the existence of this: https://just.systems/man/en/chapter_51.html#invoking-justfiles-in-other-directories

@thnee
Copy link

thnee commented Oct 23, 2024

It would be very useful if just had support for local files, similar to how mise does it.

For inspiration, see the mise docs regarding support for various filenames.
It is common to have .mise.toml checked into the repo, and have .mise.local.toml ignored and not checked in.

It is common to have some personal just commands in a specific project, that are not suitable for sharing with others.
So it would be great if just would support local files the same way as mise does.
For example, load all of these files from the target directory: justfile, local.justfile, .local.justfile.
Or maybe even load all files that end with the extensions .justfile and .just?

This is different from having a module system.
The module system requires adding a statement like mod local in the project justfile, which causes a git diff.
And it requires prefixing all the commands with the module name, like just local do-stuff.
And they run in a different context, they do not extend the project justfile.

And it is different from invoking user just files
User just files requires prefixing the command with -g.
And they run in a different context, they do not extend the project justfile.

And it is different from invoking justfiles in other directories.
Justfiles in other directories requires prefixing the command with the directory name.
And they run in a different context, they do not extend the project justfile.

The goal of having a local file is to be able to extend the project justfile in a seamless way.
There should be no need to specify anything in the project justfile or on the command line for it to be loaded.
And the main file and local file should just be concatenated/merged into one file at runtime.
So the commands in the local file would be executed the same way as the ones in the main file.
And the commands in the local file could use the commands from the main file as dependencies.

@casey
Copy link
Owner

casey commented Oct 30, 2024

You should be able to do:

import? '~/.local.just'

If ~/.local.just exists, the recipes will be imported in the current justfile. Comment or reopen if there are shortcomings with this approach!

@casey casey closed this as completed Oct 30, 2024
@kvenn
Copy link

kvenn commented Nov 7, 2024

Wow this is a great solve, thanks @casey

I won't say this is a shortcoming, but more a feature request.

I'd like a handful of just commands to be available globally. I could add them into my zshrc, but I'm fond of justfile syntax. I have many repos with many engineers and it would be challenging to manage adding the optional import to all of them.

So I guess my request: a machine-level config that would automatically apply for all directories (or all sub directories).

Or I'd be happy for a workaround! Maybe a zsh auto-apply? I'm just not familiar enough with the cool stuff just can do.

Either way, thanks for the reply and big fan of the repo!

@casey
Copy link
Owner

casey commented Nov 9, 2024

@kvenn Does the --global-justfile option help? This allows you to call recipes from a global justfile. You do need to supply a flag, -g for short, and you can't depend on recipes from the global justfile, so this might not be useful if you need to depend on those recipes.

I don't know if an auto-import mechanism would be useful. I think it might be pretty confusing, since you would get conflicts if recipes in the auto-import had the same name as those in the justfile, and justfiles which depended on recipes in the auto import wouldn't work if the setting wasn't set, and it would be pretty mysterious what was going wrong.

@kvenn
Copy link

kvenn commented Nov 9, 2024

You're a legend! I was on just 1.22 so didn't even know about this.

I created an alias and it's working like a dream.

# Alias to call global recipes in ~/.config/just/justfile
alias jg="just --global-justfile"

Do you know if there's any way to get the global recipes to show up in the shell completion?

@casey
Copy link
Owner

casey commented Nov 9, 2024

Dope, glad that works for you!

I don't know how to get global recipes to show up in shell completions, unfortunately. Recipe completion is pretty hacked together.

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