*** Wartungsfenster jeden ersten Mittwoch vormittag im Monat ***

Skip to content
Snippets Groups Projects
Commit dc1360dd authored by Moser, Maximilian's avatar Moser, Maximilian
Browse files

cli: add commands for showing the stored JSON for records/drafts

parent 30980ddd
No related branches found
No related tags found
No related merge requests found
...@@ -23,6 +23,7 @@ from .options import ( ...@@ -23,6 +23,7 @@ from .options import (
option_owners, option_owners,
option_pid_type, option_pid_type,
option_pid_value, option_pid_value,
option_pretty_print,
option_vanity_pid, option_vanity_pid,
) )
from .utils import ( from .utils import (
...@@ -147,6 +148,23 @@ def create_draft(metadata_path, publish, user, owners, vanity_pid): ...@@ -147,6 +148,23 @@ def create_draft(metadata_path, publish, user, owners, vanity_pid):
click.secho(recid, fg="green") click.secho(recid, fg="green")
@drafts.command("show")
@option_pid_value
@option_pid_type
@option_as_user
@option_pretty_print
@with_appcontext
def show_draft(pid, pid_type, user, pretty_print):
"""Show the stored data for the specified draft."""
pid = convert_to_recid(pid, pid_type)
identity = get_identity_for_user(user)
service = get_record_service()
draft = service.read_draft(id_=pid, identity=identity)
indent = 2 if pretty_print else None
data = json.dumps(draft.data, indent=indent)
click.echo(data)
@drafts.command("update") @drafts.command("update")
@click.argument("metadata_file", type=click.File("r")) @click.argument("metadata_file", type=click.File("r"))
@option_pid_value @option_pid_value
......
...@@ -75,6 +75,15 @@ option_vanity_pid = click.option( ...@@ -75,6 +75,15 @@ option_vanity_pid = click.option(
help="vanity PID, to assign to the object (not recommended)", help="vanity PID, to assign to the object (not recommended)",
) )
option_pretty_print = click.option(
"--pretty-print",
"-P",
"pretty_print",
default=False,
is_flag=True,
help="pretty-print the result",
)
# user management options # user management options
option_only_list_active_users = click.option( option_only_list_active_users = click.option(
......
...@@ -21,6 +21,7 @@ from .options import ( ...@@ -21,6 +21,7 @@ from .options import (
option_pid_type, option_pid_type,
option_pid_value, option_pid_value,
option_pid_values, option_pid_values,
option_pretty_print,
) )
from .utils import ( from .utils import (
convert_to_recid, convert_to_recid,
...@@ -62,6 +63,23 @@ def list_records(user): ...@@ -62,6 +63,23 @@ def list_records(user):
raise raise
@records.command("show")
@option_pid_value
@option_pid_type
@option_as_user
@option_pretty_print
@with_appcontext
def show_record(pid, pid_type, user, pretty_print):
"""Show the stored data for the specified draft."""
pid = convert_to_recid(pid, pid_type)
identity = get_identity_for_user(user)
service = get_record_service()
record = service.read(id_=pid, identity=identity)
indent = 2 if pretty_print else None
data = json.dumps(record.data, indent=indent)
click.echo(data)
@records.command("update") @records.command("update")
@click.argument("metadata_file", type=click.File("r")) @click.argument("metadata_file", type=click.File("r"))
@option_pid_value @option_pid_value
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment