xtfc / mold

A fresh (ironic? maybe!) approach to project chores.
https://xtfc.org/mold
MIT License
7 stars 0 forks source link

Require environments to be declared before use in conditionals #120

Open scizzorz opened 4 years ago

scizzorz commented 4 years ago

As I've started to more heavily parameterize my moldfiles, I've found that one of the initial goals of Mold - being a quick source of "what can I do in this project" - is falling apart. I often have something like the following:

if foo {
  var OBJ = "foo"
}
if bar {
  var OBJ = "bar"
}

if dev {
  var ENV = "dev"
}
if prod {
  var ENV = "prod"
}

recipe deploy {
  $ "foo $ENV $OBJ"
}

Which yields a rather useless default command listing, as simply running mold deploy isn't sufficient; you actually need to run mold deploy -a foo -a prod or some other combination. If environments had to be declared ahead of time, the default listing could also describe them as well.

Another feature this could provide would be to enable some sort of automatic enabling of environments under some conditions? That seems like it's a bit bigger of a feature, though. For example, in most CI tools, the environment variable $CI is automatically declared. Because Mold has no way to check for that, I often use a -a ci flag in CI and the corresponding if ci or if ~ci blocks handle special cases for CI/non-CI.

This particular example also makes me wonder if there would be some way to parameterize the recipe differently, but that's another topic