Skip to content

Commit

Permalink
Move setting leaf title from CLI to model
Browse files Browse the repository at this point in the history
  • Loading branch information
evilmarty committed Jun 29, 2024
1 parent 2631fbc commit 424b2b4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
11 changes: 1 addition & 10 deletions src/safaribookmarks/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@ def with_bookmarks(
def lookup(self, title: str, root: ChildrenType) -> Optional[ChildrenType]:
if title.lower() == str(root.web_bookmark_uuid).lower():
return root
elif isinstance(root, WebBookmarkTypeLeaf):
leaf = cast(WebBookmarkTypeLeaf, root)
if leaf.uri_dictionary.get("title") == title:
return leaf
elif getattr(root, "title", None) == title:
return root
elif isinstance(root, WebBookmarkTypeList):
Expand Down Expand Up @@ -185,12 +181,7 @@ def edit(self, args):
if target is None:
raise ValueError("Target not found")
if title := args.title:
if isinstance(target, WebBookmarkTypeList):
target.title = title
elif isinstance(target, WebBookmarkTypeLeaf):
target.uri_dictionary["title"] = title
else:
raise ValueError("Cannot update target title")
target.title = title
if url := args.url:
if isinstance(target, WebBookmarkTypeLeaf):
target.url_string = url
Expand Down
8 changes: 8 additions & 0 deletions src/safaribookmarks/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ class WebBookmarkTypeLeaf(WebBookmarkType):
url_string: str = Field(alias="URLString")
uri_dictionary: dict[str, str] = Field(alias="URIDictionary", default_factory=dict)

@property
def title(self) -> str:
return self.uri_dictionary.get("title", "")

@title.setter
def title(self, value) -> None:
self.uri_dictionary["title"] = value


class WebBookmarkTypeList(WebBookmarkType):
web_bookmark_type: Literal["WebBookmarkTypeList"] = Field(
Expand Down
1 change: 1 addition & 0 deletions tests/support/fixtures/list-leaf.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Safari Bookmarks CLI leaf B441CA58-1880-4151-929E-743090B66587 https://github.com/evilmarty/safari-bookmarks-cli

0 comments on commit 424b2b4

Please sign in to comment.