Page Menu
Home
Software Heritage
Search
Configure Global Search
Log In
Files
F7124863
D4139.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Subscribers
None
D4139.diff
View Options
diff --git a/swh/model/cli.py b/swh/model/cli.py
--- a/swh/model/cli.py
+++ b/swh/model/cli.py
@@ -9,8 +9,9 @@
# WARNING: do not import unnecessary things here to keep cli startup time under
# control
import click
-from swh.core.cli import swh as swh_cli_group
+from swh.core.cli import swh as swh_cli_group
+from swh.model.identifiers import SWHID
CONTEXT_SETTINGS = dict(help_option_names=["-h", "--help"])
@@ -25,17 +26,19 @@
class SWHIDParamType(click.ParamType):
- name = "persistent identifier"
+ """Click argument that accepts SWHID and return them as
+ :class:`swh.model.identifiers.SWHID` instances """
+
+ name = "SWHID"
- def convert(self, value, param, ctx):
+ def convert(self, value, param, ctx) -> SWHID:
from swh.model.exceptions import ValidationError
from swh.model.identifiers import parse_swhid
try:
- parse_swhid(value)
- return value # return as string, as we need just that
+ return parse_swhid(value)
except ValidationError as e:
- self.fail("%s is not a valid SWHID. %s." % (value, e), param, ctx)
+ self.fail(f'"{value}" is not a valid SWHID: {e}', param, ctx)
def swhid_of_file(path):
@@ -209,7 +212,7 @@
if verify:
swhid = next(results)[1]
- if verify == swhid:
+ if str(verify) == swhid:
click.echo("SWHID match: %s" % swhid)
sys.exit(0)
else:
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Dec 21 2024, 9:57 PM (11 w, 4 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3226185
Attached To
D4139: cli: make SWHIDParamType return SWHID type instead of string
Event Timeline
Log In to Comment