Skip to content

Commit

Permalink
Merge pull request #69 from cfengine/remove
Browse files Browse the repository at this point in the history
Made it possible to remove modules added by URL
  • Loading branch information
olehermanse committed Nov 5, 2021
2 parents 53590b0 + 6145141 commit 204aa0d
Showing 1 changed file with 28 additions and 6 deletions.
34 changes: 28 additions & 6 deletions cfbs/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -576,15 +576,37 @@ def _get_module_by_name(name) -> dict:
return module
return None

def _get_modules_by_url(name) -> list:
r = []
for module in modules:
if "url" in module and module["url"] == name:
r.append(module)
return r

num_removed = 0
for name in to_remove:
module = _get_module_by_name(name)
if module:
print("Removing module '%s'" % name)
modules.remove(module)
num_removed += 1
if name.startswith(("https://", "ssh://", "git://")):
matches = _get_modules_by_url(name)
if not matches:
user_error("Could not find module with URL '%s'" % name)
for module in matches:
answer = (
"yes"
if non_interactive
else input("Do you wish to remove '%s'? [y/N] " % module["name"])
)
if answer.lower() in ("yes", "y"):
print("Removing module '%s'" % module["name"])
modules.remove(module)
num_removed += 1
else:
print("Module '%s' not found" % name)
module = _get_module_by_name(name)
if module:
print("Removing module '%s'" % name)
modules.remove(module)
num_removed += 1
else:
print("Module '%s' not found" % name)

put_definition(definition)
if num_removed:
Expand Down

0 comments on commit 204aa0d

Please sign in to comment.