From d52549f3b42c2ecee2230880edcb9ac8cf1af33f Mon Sep 17 00:00:00 2001
From: Stefano Zacchiroli <zack@upsilon.cc>
Date: Fri, 17 Apr 2020 17:42:16 +0200
Subject: [PATCH] CLI: add test for swh identify w/o args

and user required=True to check that, as it is the preferred way
---
 swh/model/cli.py            | 4 +---
 swh/model/tests/test_cli.py | 4 ++++
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/swh/model/cli.py b/swh/model/cli.py
index 5b3969af..ad7e2f5f 100644
--- a/swh/model/cli.py
+++ b/swh/model/cli.py
@@ -159,7 +159,7 @@ def identify_object(obj_type, follow_symlinks, obj):
     type=PidParamType(),
     help="reference identifier to be compared with computed one",
 )
-@click.argument("objects", nargs=-1)
+@click.argument("objects", nargs=-1, required=True)
 def identify(obj_type, verify, show_filename, follow_symlinks, objects):
     """Compute the Software Heritage persistent identifier (SWHID) for the given
     source code object(s).
@@ -190,8 +190,6 @@ def identify(obj_type, verify, show_filename, follow_symlinks, objects):
       swh:1:snp:510aa88bdc517345d258c1fc2babcd0e1f905e93	helloworld.git
 
     """  # NoQA  # overlong lines in shell examples are fine
-    if not 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 6c9c7517..21eb8c5c 100644
--- a/swh/model/tests/test_cli.py
+++ b/swh/model/tests/test_cli.py
@@ -26,6 +26,10 @@ class TestIdentify(DataMixin, unittest.TestCase):
         self.assertEqual(result.exit_code, 0)
         self.assertEqual(result.output.split()[0], pid)
 
+    def test_no_args(self):
+        result = self.runner.invoke(cli.identify)
+        self.assertNotEqual(result.exit_code, 0)
+
     def test_content_id(self):
         """identify file content"""
         self.make_contents(self.tmpdir_name)
-- 
GitLab