Repository: bskinn/sphobjinv

Issue:
Revise CLI to make read-from-stdin incompatible with '-u'
Ambiguous/inconsistent set of inputs, otherwise.

- [x] Implementation
- [x] Tests
- [x] Docs

Comments:

Patch:
diff --git a/doc/source/cli/convert.rst b/doc/source/cli/convert.rst
index 5d501ad..ac49179 100644
--- a/doc/source/cli/convert.rst
+++ b/doc/source/cli/convert.rst
@@ -158,7 +158,7 @@ If processing of JSON files by API URL is desirable, please
     Path (or URL, if :option:`--url` is specified) to file to be converted.
 
     If passed as ``-``, |soi| will attempt import of a plaintext or JSON
-    inventory from ``stdin``.
+    inventory from ``stdin`` (incompatible with :option:`--url`).
 
 .. option:: outfile
 
@@ -191,7 +191,8 @@ If processing of JSON files by API URL is desirable, please
 
 .. option:: -u, --url
 
-    Treat :option:`infile` as a URL for download.
+    Treat :option:`infile` as a URL for download. Cannot be used when
+    :option:`infile` is passed as ``-``.
 
 .. option:: -e, --expand
 
diff --git a/doc/source/cli/suggest.rst b/doc/source/cli/suggest.rst
index 6ffccb8..67de7e2 100644
--- a/doc/source/cli/suggest.rst
+++ b/doc/source/cli/suggest.rst
@@ -67,7 +67,7 @@ If download of JSON files by URL is desirable, please
     Path (or URL, if :option:`--url` is specified) to file to be searched.
 
     If passed as ``-``, |soi| will attempt import of a plaintext or JSON
-    inventory from ``stdin``.
+    inventory from ``stdin`` (incompatible with :option:`--url`).
 
 .. option:: search
 
@@ -103,7 +103,8 @@ If download of JSON files by URL is desirable, please
 
 .. option:: -u, --url
 
-    Treat :option:`infile` as a URL for download.
+    Treat :option:`infile` as a URL for download. Cannot be used when
+    :option:`infile` is passed as ``-``.
 
 
 
diff --git a/src/sphobjinv/cli/core.py b/src/sphobjinv/cli/core.py
index b74fd66..9e06b0b 100644
--- a/src/sphobjinv/cli/core.py
+++ b/src/sphobjinv/cli/core.py
@@ -203,6 +203,8 @@ def main():
     # These inventory-load functions should call
     # sys.exit(n) internally in error-exit situations
     if params[PrsConst.URL]:
+        if params[PrsConst.INFILE] == "-":
+            prs.error("argument -u/--url not allowed with '-' as infile")
         inv, in_path = inv_url(params)
     elif params[PrsConst.INFILE] == "-":
         inv = inv_stdin(params)
diff --git a/src/sphobjinv/cli/parser.py b/src/sphobjinv/cli/parser.py
index ae3a47a..b034ba6 100644
--- a/src/sphobjinv/cli/parser.py
+++ b/src/sphobjinv/cli/parser.py
@@ -299,9 +299,8 @@ def getparser():
     spr_convert.add_argument(
         "-" + PrsConst.QUIET[0],
         "--" + PrsConst.QUIET,
-        help="Suppress printing of status messages "
-        "and overwrite output files "
-        "without prompting",
+        help="Suppress printing of status messages and "
+        "overwrite output files without prompting",
         action="store_true",
     )
 
@@ -309,7 +308,9 @@ def getparser():
     spr_convert.add_argument(
         "-" + PrsConst.URL[0],
         "--" + PrsConst.URL,
-        help="Treat 'infile' as a URL for download",
+        help="Treat 'infile' as a URL for download. Cannot be used with --{}.".format(
+            PrsConst.URL
+        ),
         action="store_true",
     )
 
@@ -358,7 +359,9 @@ def getparser():
     spr_suggest.add_argument(
         "-" + PrsConst.URL[0],
         "--" + PrsConst.URL,
-        help="Treat 'infile' as a URL for download",
+        help="Treat 'infile' as a URL for download. Cannot be used with --{}.".format(
+            PrsConst.URL
+        ),
         action="store_true",
     )
 


Test patch:
diff --git a/tests/test_cli.py b/tests/test_cli.py
index a122112..6c0e450 100644
--- a/tests/test_cli.py
+++ b/tests/test_cli.py
@@ -460,6 +460,12 @@ class TestFail:
             file_url = "file:///" + str(in_path.resolve())
             run_cmdline_test(["convert", "plain", "-u", file_url], expect=1)
 
+    def test_clifail_no_url_with_stdin(self, run_cmdline_test):
+        """Confirm parser exit when -u passed with "-" infile."""
+        with stdio_mgr() as (in_, out_, err_):
+            run_cmdline_test(["convert", "plain", "-u", "-"], expect=2)
+            assert "--url not allowed" in err_.getvalue()
+
 
 class TestStdio:
     """Tests for the stdin/stdout functionality."""