diff --git a/invenio_utilities_tuw/cli/drafts.py b/invenio_utilities_tuw/cli/drafts.py index a222b5851ffba4fb240f3bd15194d841f1c4944f..50f5479c58aa48472ba36f89cd43f62446d37aa9 100644 --- a/invenio_utilities_tuw/cli/drafts.py +++ b/invenio_utilities_tuw/cli/drafts.py @@ -23,6 +23,7 @@ from .options import ( option_owners, option_pid_type, option_pid_value, + option_pretty_print, option_vanity_pid, ) from .utils import ( @@ -147,6 +148,23 @@ def create_draft(metadata_path, publish, user, owners, vanity_pid): 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") @click.argument("metadata_file", type=click.File("r")) @option_pid_value diff --git a/invenio_utilities_tuw/cli/options.py b/invenio_utilities_tuw/cli/options.py index de3be22a1a232763d00fef2ae9bf769cdae3cfaa..ff7d7614d6d31a7d3ac9378272104e552c42ebc0 100644 --- a/invenio_utilities_tuw/cli/options.py +++ b/invenio_utilities_tuw/cli/options.py @@ -75,6 +75,15 @@ option_vanity_pid = click.option( 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 option_only_list_active_users = click.option( diff --git a/invenio_utilities_tuw/cli/records.py b/invenio_utilities_tuw/cli/records.py index e621932702f7b83f50ab58ea7e6117f23f3f675d..9db3c372f69800fa6fdebe00a1c83f7ccf076c5c 100644 --- a/invenio_utilities_tuw/cli/records.py +++ b/invenio_utilities_tuw/cli/records.py @@ -21,6 +21,7 @@ from .options import ( option_pid_type, option_pid_value, option_pid_values, + option_pretty_print, ) from .utils import ( convert_to_recid, @@ -62,6 +63,23 @@ def list_records(user): 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") @click.argument("metadata_file", type=click.File("r")) @option_pid_value