xonixx / makesure

Simple task/command runner with declarative goals and dependencies
https://makesure.dev
MIT License
340 stars 5 forks source link

Make `@use_lib` apply also to `@reached_if` #76

Closed pcrockett closed 2 years ago

pcrockett commented 2 years ago

I have found makesure to be a really helpful way to document my laptop configurations in such a way that, when my laptop dies, I can easily reconfigure a new one with a single makesure command.

Here's a small example of the kind of Makesurefile I'm writing:

@lib

service_exists() {
  local service_name="${1}"
  systemctl list-unit-files --full --type=service | grep --fixed-strings "${service_name}.service" &> /dev/null
}

@goal apt_updated @private
  sudo apt-get update

@goal iptables_persistent_installed @private
@use_lib
@depends_on apt_updated
@reached_if service_exists iptables
  sudo apt-get install --yes iptables-persistent

@goal default
@depends_on iptables_persistent_installed

My actual Makesurefile already has dozens of goals in it, many of them very similar to the iptables_persistent_installed goal above.

As it is now, I can't actually do @reached_if service_exists iptables because @use_lib doesn't apply there. Instead I have to manually copy / paste / modify my @reached_if statements to include the full command, like so:

@goal iptables_persistent_installed @private
@depends_on apt_updated
@reached_if systemctl list-unit-files --full --type=service | grep --fixed-strings iptables.service &> /dev/null
  sudo apt-get install --yes iptables-persistent

That gets messy really quickly. The best workaround I have is also pretty ugly, but it's better than nothing:

@reached_if source util.sh && service_exists iptables

Is it possible to make our libs usable from within @reached_if?

xonixx commented 2 years ago

Hi @pcrockett. I'm glad that you found the tool useful for your needs. Definitely what you propose makes sense, the current behavior is indeed inconsistent. I'm especially greatful for your pull request. I will check it soon.

xonixx commented 2 years ago

Thanks you once again @pcrockett. The PR is merged with minor improvements by me. Btw I encountered one other bug thanks to this report (#78). Once fixed - I'll release the new version. Stay tuned!