diff --git a/invenio_utilities_tuw/cli/drafts.py b/invenio_utilities_tuw/cli/drafts.py index dcc616fb563ca9174b832751106e25c63fb166c6..704ee28b90d460e57122039c802b40972548b00c 100644 --- a/invenio_utilities_tuw/cli/drafts.py +++ b/invenio_utilities_tuw/cli/drafts.py @@ -24,6 +24,7 @@ from .options import ( option_pid_type, option_pid_value, option_pretty_print, + option_raw, option_vanity_pid, ) from .utils import ( @@ -156,15 +157,17 @@ def create_draft(metadata_path, publish, user, owners, vanity_pid): @option_pid_type @option_as_user @option_pretty_print +@option_raw @with_appcontext -def show_draft(pid, pid_type, user, pretty_print): +def show_draft(pid, pid_type, user, pretty_print, raw): """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) + data = draft._record.model.json if raw else draft.data + data = json.dumps(data, indent=indent) click.echo(data) diff --git a/invenio_utilities_tuw/cli/options.py b/invenio_utilities_tuw/cli/options.py index 62dcc433e57e78cb31fc295f49a1fef680c3067d..afe860b7115d247148a2c3b6fbbdfad6b11151c1 100644 --- a/invenio_utilities_tuw/cli/options.py +++ b/invenio_utilities_tuw/cli/options.py @@ -83,6 +83,14 @@ option_pretty_print = click.option( help="pretty-print the result", ) +option_raw = click.option( + "--raw", + "raw", + default=False, + is_flag=True, + help="print the raw or projected data", +) + # 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 ec2ca0cf46bc4770de29b29199b554f21db2237d..d656d595c3f6f969a8e209380c55eaa537e3fd18 100644 --- a/invenio_utilities_tuw/cli/records.py +++ b/invenio_utilities_tuw/cli/records.py @@ -23,6 +23,7 @@ from .options import ( option_pid_value, option_pid_values, option_pretty_print, + option_raw, ) from .utils import ( convert_to_recid, @@ -70,15 +71,17 @@ def list_records(user): @option_pid_type @option_as_user @option_pretty_print +@option_raw @with_appcontext -def show_record(pid, pid_type, user, pretty_print): +def show_record(pid, pid_type, user, pretty_print, raw): """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) + data = record._record.model.json if raw else record.data + data = json.dumps(data, indent=indent) click.echo(data)