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

Allow setting duplicate settings #2563

Open
xavdid opened this issue Jan 7, 2025 · 5 comments
Open

Allow setting duplicate settings #2563

xavdid opened this issue Jan 7, 2025 · 5 comments

Comments

@xavdid
Copy link
Contributor

xavdid commented Jan 7, 2025

I've got two justfiles across related projects. Each should work on their own, but the child imports the parent for extra (optional) functionality. It's roughly:

# ~/parent/justfile
base:
  echo "in base!"

# ~/child/justfile
import? '../parent/justfile'
child:
  echo "in child!"

And it works great!

But, I want to set quiet in both files. If I always used child when parent was present, then I could just piggyback on a definition in parent. Or, exclude it from parent and set it in each child. But, since each justfile should work independently, I find myself wanting to set it in both places. Today, I get an error:

Setting `quiet` first set on line 1 is redefined on line 4

I'd expect it to follow the existing allow-duplicate-variables behavior: last setting wins.

Is this sort of thing possible today? Alternatively, would you be open to a PR?

@casey
Copy link
Owner

casey commented Jan 9, 2025

Settings and variables are distinct, so allow-duplicate-variables doesn't help with settings.

I'm a bit hesitant to add more allow-duplicate-* settings.

They're really a hack to, originally, work around the lack of modules, and now to work around limitations of modules. Modules have their own settings scope, so you can put whatever settings you want inside of submodules and they won't conflict. The biggest limitation is that you can't call recipes in child modules, which is, I think, the main reason why often using imports won't help with particular use cases.

@xavdid
Copy link
Contributor Author

xavdid commented Jan 14, 2025

Right, in our case we're using these across repos (only some of which are public). The example parent/justfile is a close-source repo while (the 7 different) children justfiles are in open source repos. The children files should work on their own, but employees working on those repos have access to additional internal recipes defined in the parent (that can be called from the child directories).

Quiet isn't a big deal (and we can prefix @ on every parent recipe), but a better solution would be useful. Doesn't need to be an allow-duplicate-settings specifically though. Anything that would let us do "set this setting if not set" would be really useful. Maybe something like set? quiet or set quiet ?= true?

@casey
Copy link
Owner

casey commented Jan 15, 2025

set? quiet isn't great, because it introduces order dependence, which is something that just tries to avoid. When not using allow-duplicate settings or recipes, the order of everything in a justfile doesn't matter, which is a simpler mental model.

@xavdid
Copy link
Contributor Author

xavdid commented Jan 15, 2025

What if there's no syntax changes, it's only an error to set a setting to a new value, but a no-op to set it to the same value again?

So multiple files can all have the same setting, but disagreements would error out (same as today).

@casey
Copy link
Owner

casey commented Jan 16, 2025

That's definitely less bad. I vaguely worry that it would mask user error, but I think it would be okay, and probably what most people need. I want to let this feature request sit for a little bit, and collect some feedback and see if anyone else needs it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants