update params and args and base dir

This commit is contained in:
Sofía Aritz 2025-06-09 22:47:38 +02:00
parent 9d99d45d68
commit 77ecf6f8a3
Signed by: sofia
GPG key ID: 5A1485B4CCCDDB4A
2 changed files with 28 additions and 21 deletions

View file

@ -3,18 +3,20 @@
## Usage
```sh
usage: journal [-h] [--journal-dir JOURNAL_DIR] [--editor EDITOR] {create,edit,delete}
usage: journal [-h] {create,edit,delete}
Journal
Journal, safely write down your thoughts.
positional arguments:
{create,edit,delete} Command to run (create a new entry, or view and edit an existing one)
options:
-h, --help show this help message and exit
--journal-dir JOURNAL_DIR
Path to your journal directory (default $JOURNAL_DIR or ~/.journal)
--editor EDITOR Editor to use (default $EDITOR or nano)
environment variables:
- The journal data directory defaults to $JOURNAL_DATA_HOME, or if unset, $XDG_DATA_HOME,
or ~/.local/share/com.sofiaritz.Journal/entries by default.
- The editor used defaults to $EDITOR environment variable or falls back to 'nano'.
```
## Installation

View file

@ -10,12 +10,20 @@ import getpass
import argparse
import os
import shlex
import shutil
import logging
import sys
import textwrap
FRONTMATTER_SEPARATOR = "+++"
JOURNAL_DIR = Path(os.path.expanduser(os.environ.get("JOURNAL_DIR", "~/.journal")))
NAMESPACE = "com.sofiaritz.Journal"
_DATA_HOME = Path(
os.getenv("JOURNAL_DATA_HOME",
os.getenv("XDG_DATA_HOME", Path.home() / ".local" / "share"))
)
JOURNAL_DIR = Path(_DATA_HOME / NAMESPACE / "entries")
EDITOR = os.environ.get("EDITOR", "nano"),
logger = logging.getLogger(__name__)
@ -183,35 +191,32 @@ def delete_entry(base_path: Path):
return
def main():
parser = argparse.ArgumentParser(description="Journal")
description = "Journal, safely write down your thoughts."
epiloge = """environment variables:
- The journal data directory defaults to $JOURNAL_DATA_HOME, or if unset, $XDG_DATA_HOME,
or ~/.local/share/com.sofiaritz.Journal/entries by default.
- The editor used defaults to $EDITOR environment variable or falls back to 'nano'.
"""
parser = argparse.ArgumentParser(description=description, epilog=epiloge, formatter_class=argparse.RawDescriptionHelpFormatter)
parser.add_argument(
"command",
choices=["create", "edit", "delete"],
help="Command to run (create a new entry, or view and edit an existing one)",
)
parser.add_argument(
"--journal-dir",
type=Path,
default=JOURNAL_DIR,
help="Path to your journal directory (default $JOURNAL_DIR or ~/.journal)",
)
parser.add_argument(
"--editor",
default=EDITOR,
help="Editor to use (default $EDITOR or nano)",
)
args = parser.parse_args()
base_path = args.journal_dir
base_path = JOURNAL_DIR
base_path.mkdir(parents=True, exist_ok=True)
if args.command == "create":
passphrase = getpass.getpass("Enter passphrase: ")
create_entry(passphrase, base_path, args.editor)
create_entry(passphrase, base_path, EDITOR)
elif args.command == "edit":
passphrase = getpass.getpass("Enter passphrase: ")
edit_entry(passphrase, base_path, args.editor)
edit_entry(passphrase, base_path, EDITOR)
elif args.command == "delete":
delete_entry(base_path)
else: