Browse Source

feat: Disable stdin from archivebox add

Cristian 5 years ago
parent
commit
b68c13918f
3 changed files with 11 additions and 4 deletions
  1. 4 2
      archivebox/cli/archivebox_add.py
  2. 1 2
      archivebox/main.py
  3. 6 0
      tests/test_init.py

+ 4 - 2
archivebox/cli/archivebox_add.py

@@ -10,7 +10,7 @@ from typing import List, Optional, IO
 
 from ..main import add, docstring
 from ..config import OUTPUT_DIR, ONLY_NEW
-from .logging import SmartFormatter, accept_stdin
+from .logging import SmartFormatter, reject_stdin
 
 
 @docstring(add.__doc__)
@@ -38,9 +38,10 @@ def main(args: Optional[List[str]]=None, stdin: Optional[IO]=None, pwd: Optional
         type=str,
         default=None,
         help=(
-            'URL or path to local file containing a list of links to import. e.g.:\n'
+            'URL or path to local file containing a page or list of links to import. e.g.:\n'
             '    https://getpocket.com/users/USERNAME/feed/all\n'
             '    https://example.com/some/rss/feed.xml\n'
+            '    https://example.com\n'
             '    ~/Downloads/firefox_bookmarks_export.html\n'
             '    ~/Desktop/sites_list.csv\n'
         )
@@ -54,6 +55,7 @@ def main(args: Optional[List[str]]=None, stdin: Optional[IO]=None, pwd: Optional
         help="Recursively archive all linked pages up to this many hops away"
     )
     command = parser.parse_args(args or ())
+    reject_stdin(__command__, stdin)
     add(
         import_str=command.import_path,
         import_path=None,

+ 1 - 2
archivebox/main.py

@@ -507,8 +507,7 @@ def add(import_str: Optional[str]=None,
 
     if (import_str and import_path) or (not import_str and not import_path):
         stderr(
-            '[X] You should pass either an import path as an argument, '
-            'or pass a list of links via stdin, but not both.\n',
+            '[X] You should pass an import path or a page url as an argument\n',
             color='red',
         )
         raise SystemExit(2)

+ 6 - 0
tests/test_init.py

@@ -31,3 +31,9 @@ def test_add_link(tmp_path, process):
         output_html = f.read()
     assert "Example Domain" in output_html
 
+def test_add_link_does_not_support_stdin(tmp_path, process):
+    os.chdir(tmp_path)
+    stdin_process = subprocess.Popen(["archivebox", "add"], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
+    output = stdin_process.communicate(input="example.com".encode())[0]
+    assert "does not accept stdin" in output.decode("utf-8")
+