diff --git a/docs/commands/drop.rst b/docs/commands/drop.rst index 68455f3..d58a569 100644 --- a/docs/commands/drop.rst +++ b/docs/commands/drop.rst @@ -3,13 +3,18 @@ nnote drop .. code-block:: text - nnote drop [] [-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 diff --git a/nnote/commands/drop.py b/nnote/commands/drop.py index 0c0e21c..734d456 100644 --- a/nnote/commands/drop.py +++ b/nnote/commands/drop.py @@ -6,9 +6,7 @@ @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", @@ -16,8 +14,8 @@ 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: @@ -25,15 +23,18 @@ def drop(title, directory): "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():