Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions docs/commands/drop.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@ nnote drop

.. code-block:: text

nnote drop [<title>] [-d <dir>]
nnote drop [<title> ...] [-d <dir>]

Remove a note or a directory. When dropping a directory, prompts for
confirmation if it contains files.
Remove one or more notes or a directory. Multiple titles can be passed in a
single invocation. All titles are validated before anything is deleted — if
any are missing, nothing is removed and the missing names are reported.

When dropping a directory, prompts for confirmation if it contains files.

.. code-block:: bash

nnote drop todo # remove a note
nnote drop standup -d work # remove a note inside a subdirectory
nnote drop -d work # remove the entire directory
nnote drop todo # remove a single note
nnote drop standup -d work # remove a note inside a subdirectory
nnote drop todo shopping errands # remove multiple notes at once
nnote drop mon tue wed -d work # remove multiple notes in a subdirectory
nnote drop -d work # remove the entire directory
25 changes: 13 additions & 12 deletions nnote/commands/drop.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,35 @@


@click.command()
@click.argument(
"title", required=False, default=None, shell_complete=complete_note_titles
)
@click.argument("titles", nargs=-1, shell_complete=complete_note_titles)
@click.option(
"-d",
"--directory",
default=None,
help="Subdirectory within notes dir",
shell_complete=complete_directories,
)
def drop(title, directory):
"""Remove a note or a directory."""
def drop(titles, directory):
"""Remove one or more notes or a directory."""
config = Config.load()

if config.notes_dir is None:
raise click.ClickException(
"Notes directory not configured. Run `nnote init` first."
)

if title is None and directory is None:
if not titles and directory is None:
raise click.UsageError("Provide a note title, a directory (-d), or both.")

if title:
note_path = resolve_note_path(config, title, directory)
if not note_path.exists():
raise click.ClickException(f"Note not found: {note_path}")
note_path.unlink()
click.echo(f"Removed: {note_path.name}")
if titles:
paths = [resolve_note_path(config, t, directory) for t in titles]
missing = [p for p in paths if not p.exists()]
if missing:
names = ", ".join(p.name for p in missing)
raise click.ClickException(f"Note(s) not found: {names}")
for path in paths:
path.unlink()
click.echo(f"Removed: {path.name}")
else:
dir_path = config.notes_dir / directory
if not dir_path.exists():
Expand Down