Skip to content
This repository has been archived by the owner on Jul 4, 2023. It is now read-only.

Commit

Permalink
add force option
Browse files Browse the repository at this point in the history
  • Loading branch information
Clivern committed Jun 28, 2023
1 parent 74271ec commit 5a8f999
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
Changelog
=========

Version 0.3.1
=============

- Add force option.


Version 0.3.0
=============

Expand Down
10 changes: 6 additions & 4 deletions src/flook/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ def list(tag, output):
help="Private key file used by ssh",
)
@click.option("-t", "--tags", "tags", type=click.STRING, default="", help="Host tags")
def add(name, connection, ip, port, user, password, ssh_private_key_file, tags):
@click.option("-f", "--force", "force", is_flag=True, default=False, help="Force add")
def add(name, connection, ip, port, user, password, ssh_private_key_file, tags, force):
host = Host(
str(uuid.uuid4()),
name,
Expand All @@ -119,7 +120,7 @@ def add(name, connection, ip, port, user, password, ssh_private_key_file, tags):
None,
)

return Hosts().init().add(host)
return Hosts().init().add(host, force)


# Get host sub command
Expand Down Expand Up @@ -157,11 +158,12 @@ def recipe():
help="Path to the recipe",
)
@click.option("-t", "--tags", "tags", type=click.STRING, default="", help="Recipe tags")
def add(name, path, tags):
@click.option("-f", "--force", "force", is_flag=True, default=False, help="Force add")
def add(name, path, tags, force):
return (
Recipes()
.init()
.add(name, {"path": path, "tags": tags.split(",") if "," in tags else []})
.add(name, {"path": path, "tags": tags.split(",") if "," in tags else []}, force)
)


Expand Down
5 changes: 4 additions & 1 deletion src/flook/command/hosts.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,11 @@ def init(self):
self.database.migrate()
return self

def add(self, host):
def add(self, host, force):
"""Add a new host"""
if force:
self.database.delete_host(name)

if self.database.get_host(host.name) is not None:
raise click.ClickException(f"Host with name {host.name} exists")

Expand Down
5 changes: 4 additions & 1 deletion src/flook/command/recipes.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,14 @@ def init(self):
self.database.migrate()
return self

def add(self, name, configs):
def add(self, name, configs, force):
"""Add a Recipe"""
recipe = ""
templates = []

if force:
self.database.delete_recipe(name)

if self.database.get_recipe(name) is not None:
raise click.ClickException(f"Recipe with name {name} exists")

Expand Down

0 comments on commit 5a8f999

Please sign in to comment.