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

Make @use_lib apply also to @reached_if #76

Closed
pcrockett opened this issue Nov 20, 2021 · 2 comments · Fixed by #77
Closed

Make @use_lib apply also to @reached_if #76

pcrockett opened this issue Nov 20, 2021 · 2 comments · Fixed by #77
Labels
bug Something isn't working
Milestone

Comments

@pcrockett
Copy link
Contributor

pcrockett commented Nov 20, 2021

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
Copy link
Owner

xonixx commented Nov 20, 2021

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 added a commit to pcrockett/makesure that referenced this issue Nov 20, 2021
xonixx added a commit to pcrockett/makesure that referenced this issue Nov 20, 2021
@xonixx xonixx added this to the 0.9.14 milestone Nov 20, 2021
@xonixx
Copy link
Owner

xonixx commented Nov 20, 2021

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!

@xonixx xonixx changed the title Make @use_lib apply also to @reached_if Make @use_lib apply also to @reached_if Nov 21, 2021
@xonixx xonixx added the bug Something isn't working label Nov 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants