nncli

NextCloud Notes Command Line Interface
git clone git://git.danielmoch.com/nncli.git
Log | Files | Refs | LICENSE

commit d701864f55ddc4ecdc47ca46690eb1c568a9166c
parent d10ecc9521a7f840ddb80cf2ca0aebe4944acbe8
Author: Daniel Moch <daniel@danielmoch.com>
Date:   Sun, 12 Dec 2021 21:06:55 -0500

Add stdin flag to edit subcommand

Allow the edited note contents to be passed in on the command line

Diffstat:
Mnncli/cli.py | 10+++++++---
Mnncli/nncli.py | 5++++-
2 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/nncli/cli.py b/nncli/cli.py @@ -167,7 +167,7 @@ def delete(nncli, key): """Delete an existing note.""" nncli.cli_note_delete(key, True) -@click.command() +@click.command(short_help="Edit an existing note.") @click.option( '-k', '--key', @@ -175,10 +175,14 @@ def delete(nncli, key): type=click.INT, help="Specify the note key." ) +@click.argument('from_stdin', metavar='[-]', type=STDIN_FLAG) @click.pass_obj def edit(nncli, key): - """Edit an existing note.""" - nncli.cli_note_edit(key) + """ + Edit an existing note. If - is specified, the note contents are + read from stdin, otherwise the editor will open. + """ + nncli.cli_note_edit(from_stdin, key) @click.command(short_help="Import a JSON note.") @click.argument('from_stdin', metavar='[-]', type=STDIN_FLAG) diff --git a/nncli/nncli.py b/nncli/nncli.py @@ -177,7 +177,10 @@ def cli_note_edit(self, key): self.logger.log('ERROR: Key does not exist') return - content = exec_cmd_on_note(note, self.config, self.nncli_gui, + if from_stdin: + content = ''.join(sys.stdin) + else: + content = exec_cmd_on_note(note, self.config, self.nncli_gui, self.logger) if not content: return