Skip to content

Commit

Permalink
another guard clause refactor; add another unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
znd4 committed Oct 27, 2023
1 parent c57ba48 commit ddd4112
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 16 deletions.
28 changes: 15 additions & 13 deletions pyinfra/operations/brew.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,22 +195,24 @@ def tap(src, present=True, url=None):
taps = host.get_fact(BrewTaps)
is_tapped = src in taps

if present:
if is_tapped:
if is_tapped:
if present:
host.noop("tap {0} already exists".format(src))
return

cmd = "brew tap {0}".format(src)

if url:
cmd = " ".join([cmd, url])

yield cmd
taps.append(src)
return

if is_tapped:
yield "brew untap {0}".format(src)
taps.remove(src)
return
host.noop("tap {0} does not exist".format(src))

if not present:
host.noop("tap {0} does not exist".format(src))
return

cmd = "brew tap {0}".format(src)

if url is not None:
cmd = " ".join([cmd, url])

yield cmd
taps.append(src)
return
4 changes: 1 addition & 3 deletions tests/operations/brew.tap/add_tap_url.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
"url": "https://github.com/homebrew/cask"
},
"facts": {
"brew.BrewTaps": [
"homebrew/cask"
]
"brew.BrewTaps": []
},
"commands": [
"brew tap homebrew/cask https://github.com/homebrew/cask"
Expand Down
15 changes: 15 additions & 0 deletions tests/operations/brew.tap/add_tap_url_exists.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"args": [
"homebrew/cask"
],
"kwargs": {
"url": "https://github.com/homebrew/cask"
},
"facts": {
"brew.BrewTaps": [
"homebrew/cask"
]
},
"commands": [],
"noop_description": "tap homebrew/cask already exists"
}

0 comments on commit ddd4112

Please sign in to comment.