feat: move project from poetry to pdm, rewrite from scratch and add
basic `notebooks`, `edit` and `show` commands
This commit is contained in:
parent
d9eb99b72e
commit
d3ad87211e
35 changed files with 1309 additions and 1434 deletions
34
halig/commands/show.py
Normal file
34
halig/commands/show.py
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
from pathlib import Path
|
||||
|
||||
from rich.console import Console
|
||||
from rich.markdown import Markdown
|
||||
|
||||
from halig.commands.base import BaseCommand
|
||||
from halig.encryption import Encryptor
|
||||
from halig.settings import Settings
|
||||
|
||||
|
||||
class ShowCommand(BaseCommand):
|
||||
def __init__(self, note_path: Path, settings: Settings):
|
||||
super().__init__(settings)
|
||||
|
||||
self.note_path = self.settings.notebooks_root_path / note_path
|
||||
self.encryptor = Encryptor(self.settings)
|
||||
self.console = Console()
|
||||
if self.note_path.is_dir():
|
||||
self.note_path /= f"{self.today.date()}.age"
|
||||
|
||||
if not self.note_path.exists():
|
||||
err = f"File {self.note_path.name} does not exist"
|
||||
raise ValueError(err)
|
||||
|
||||
if not self.note_path.name.endswith(".age"):
|
||||
err = f"File {self.note_path.name} is not a valid AGE file"
|
||||
raise ValueError(err)
|
||||
|
||||
def run(self):
|
||||
with self.note_path.open("rb") as f:
|
||||
data = f.read()
|
||||
contents = self.encryptor.decrypt(data)
|
||||
md_contents = Markdown(contents.decode())
|
||||
self.console.print(md_contents)
|
||||
Loading…
Add table
Add a link
Reference in a new issue