From 7b2cc1fafd9174369897668e760cd20134b2bab9 Mon Sep 17 00:00:00 2001 From: Stefano Zacchiroli <zack@upsilon.cc> Date: Fri, 17 Apr 2020 17:25:03 +0200 Subject: [PATCH] CLI: require explicit "-" to identify via stdin --- swh/model/cli.py | 4 +++- swh/model/tests/test_cli.py | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/swh/model/cli.py b/swh/model/cli.py index 3947d826..5b3969af 100644 --- a/swh/model/cli.py +++ b/swh/model/cli.py @@ -169,6 +169,8 @@ def identify(obj_type, verify, show_filename, follow_symlinks, objects): \b https://docs.softwareheritage.org/devel/swh-model/persistent-identifiers.html + Tip: you can pass "-" to identify the content of standard input. + \b Examples: @@ -189,7 +191,7 @@ def identify(obj_type, verify, show_filename, follow_symlinks, objects): """ # NoQA # overlong lines in shell examples are fine if not objects: - objects = ["-"] + raise click.UsageError("no object given") if verify and len(objects) != 1: raise click.BadParameter("verification requires a single object") diff --git a/swh/model/tests/test_cli.py b/swh/model/tests/test_cli.py index fac1d89d..6c9c7517 100644 --- a/swh/model/tests/test_cli.py +++ b/swh/model/tests/test_cli.py @@ -38,7 +38,7 @@ class TestIdentify(DataMixin, unittest.TestCase): """identify file content""" self.make_contents(self.tmpdir_name) for _, content in self.contents.items(): - result = self.runner.invoke(cli.identify, input=content["data"]) + result = self.runner.invoke(cli.identify, ["-"], input=content["data"]) self.assertPidOK(result, "swh:1:cnt:" + hash_to_hex(content["sha1_git"])) def test_directory_id(self): -- GitLab