Skip to content

Commit

Permalink
FEATURE : Ability to delete notes and child notes.
Browse files Browse the repository at this point in the history
  • Loading branch information
crdoconnor committed Jan 8, 2024
1 parent 5a566bd commit 3a1ecb1
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
13 changes: 4 additions & 9 deletions hitch/story/rm.story
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,26 @@ Delete:
- orji:
env:
ORJITMP: ./tmp
cmd: rm 0
cmd: rm org/simple.org//0
output: |
Deleted note(s) successfully

- file contents:
filename: org/simple.org
contents: |
* Top note
** Subnote 1
** Subnote 2
* DONE Done item
* DONE Done item

Children:
steps:
- orji:
env:
ORJITMP: ./tmp
cmd: rm 0 --children
cmd: rm org/simple.org//0 --children
output: |
Deleted note(s) successfully

- file contents:
filename: org/simple.org
contents: |
* Top note
** Subnote 1
** Subnote 2
* DONE Done item
* DONE Done item
10 changes: 10 additions & 0 deletions orji/note.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,16 @@ def from_indexlookup(self, indexlookup):

return Note(node, self._loader, self._rg)

def delete(self):
parent = self._node.parent
node_index = [
i for i, node in enumerate(parent.children) if node == self._node
][0]
del parent.children[node_index]

def delete_children(self):
self._node.children = []

def has(self, lookup):
return Lookup(lookup, relative_to=self).exists(loader=self._loader)

Expand Down
11 changes: 9 additions & 2 deletions orji/remove.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import click
from .tempdir import TempDir
from .lookup import Lookup
from .loader import Loader
from pathlib import Path


@click.command()
Expand All @@ -14,8 +16,13 @@
def remove(location, children):
temp_dir = TempDir()
temp_dir.create()
loader = Loader(temp_dir)
lookup = Lookup(location)
lookup
# Path(lookup.filepath).write_text(str(write_note))
item = lookup.load(loader)
if children:
item.delete_children()
else:
item.delete()
Path(lookup.filepath).write_text(str(item._org))
click.echo("Deleted note(s) successfully")
temp_dir.destroy()

0 comments on commit 3a1ecb1

Please sign in to comment.