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

Support only_if and not_if inside a define #271

Merged
merged 3 commits into from
Nov 12, 2018
Merged

Conversation

sue445
Copy link
Member

@sue445 sue445 commented Oct 23, 2018

c.f. #262

Example

define :some_definition do
end

# this is executed
some_definition do
  only_if "exit 0"
end

# this is not executed
some_definition do
  only_if "exit 1"
end

Close #262
Close #161

@sue445 sue445 changed the title [WIP] Support only_if and not_if to definition [WIP] Support only_if and not_if inside a define Oct 23, 2018
@sue445 sue445 force-pushed the define_not_if_and_only_if branch from 1e59f57 to 2ea0535 Compare October 23, 2018 23:25
@sue445 sue445 changed the title [WIP] Support only_if and not_if inside a define Support only_if and not_if inside a define Oct 28, 2018
@sue445
Copy link
Member Author

sue445 commented Oct 28, 2018

@unasuke I removed WIP. Please review this 🙇

@ryotarai
Copy link
Member

This implementation evaluates only_if and not_if in the phase of loading recipes but only_if and not_if of normal resources (!= definition) are evaluated in the running phase.
For instance, in this recipe, echo is not executed:

execute 'touch /tmp/a'

define :echo do
  execute 'echo B'
end

execute 'echo A' do
  only_if 'test -f /tmp/a'
end

echo 'echo' do
  only_if 'test -f /tmp/a'
end
 INFO : Starting Itamae...
 INFO : Recipe: /Users/ryotarai/src/github.com/itamae-kitchen/itamae/tmp/a.rb
 INFO :   execute[touch /tmp/a] executed will change from 'false' to 'true'
 INFO :   execute[echo A] executed will change from 'false' to 'true'

@sue445
Copy link
Member Author

sue445 commented Oct 29, 2018

@ryotarai oops... I'll fix this.

@sue445 sue445 changed the title Support only_if and not_if inside a define [WIP] Support only_if and not_if inside a define Oct 29, 2018
@sue445 sue445 force-pushed the define_not_if_and_only_if branch from deff864 to 0ae12a9 Compare November 3, 2018 13:34
@sue445 sue445 force-pushed the define_not_if_and_only_if branch from 0ae12a9 to 219e14e Compare November 3, 2018 15:57
@sue445 sue445 force-pushed the define_not_if_and_only_if branch from 219e14e to fdd5535 Compare November 3, 2018 16:16
@sue445 sue445 changed the title [WIP] Support only_if and not_if inside a define Support only_if and not_if inside a define Nov 3, 2018
@sue445
Copy link
Member Author

sue445 commented Nov 3, 2018

@ryotarai @unasuke I fixed this problem. Please review again 🙇

log that executed #271 (comment)

$ be ./bin/itamae local /tmp/test.rb
 INFO : Starting Itamae...
 INFO : Recipe: /tmp/test.rb
 INFO :   execute[touch /tmp/a] executed will change from 'false' to 'true'
 INFO :   execute[echo A] executed will change from 'false' to 'true'
 INFO :     execute[echo B] executed will change from 'false' to 'true'

@sue445 sue445 requested review from ryotarai and unasuke November 3, 2018 16:29
@unasuke
Copy link
Member

unasuke commented Nov 3, 2018

Copy link
Member

@unasuke unasuke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

Copy link
Member

@ryotarai ryotarai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@sue445 sue445 merged commit 1b6597b into master Nov 12, 2018
@sue445 sue445 deleted the define_not_if_and_only_if branch November 12, 2018 01:52
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

Successfully merging this pull request may close these issues.

3 participants