feat: Disable stdin from archivebox add
This commit is contained in:
parent
bca6a06f60
commit
b68c13918f
3 changed files with 11 additions and 4 deletions
|
@ -10,7 +10,7 @@ from typing import List, Optional, IO
|
||||||
|
|
||||||
from ..main import add, docstring
|
from ..main import add, docstring
|
||||||
from ..config import OUTPUT_DIR, ONLY_NEW
|
from ..config import OUTPUT_DIR, ONLY_NEW
|
||||||
from .logging import SmartFormatter, accept_stdin
|
from .logging import SmartFormatter, reject_stdin
|
||||||
|
|
||||||
|
|
||||||
@docstring(add.__doc__)
|
@docstring(add.__doc__)
|
||||||
|
@ -38,9 +38,10 @@ def main(args: Optional[List[str]]=None, stdin: Optional[IO]=None, pwd: Optional
|
||||||
type=str,
|
type=str,
|
||||||
default=None,
|
default=None,
|
||||||
help=(
|
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://getpocket.com/users/USERNAME/feed/all\n'
|
||||||
' https://example.com/some/rss/feed.xml\n'
|
' https://example.com/some/rss/feed.xml\n'
|
||||||
|
' https://example.com\n'
|
||||||
' ~/Downloads/firefox_bookmarks_export.html\n'
|
' ~/Downloads/firefox_bookmarks_export.html\n'
|
||||||
' ~/Desktop/sites_list.csv\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"
|
help="Recursively archive all linked pages up to this many hops away"
|
||||||
)
|
)
|
||||||
command = parser.parse_args(args or ())
|
command = parser.parse_args(args or ())
|
||||||
|
reject_stdin(__command__, stdin)
|
||||||
add(
|
add(
|
||||||
import_str=command.import_path,
|
import_str=command.import_path,
|
||||||
import_path=None,
|
import_path=None,
|
||||||
|
|
|
@ -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):
|
if (import_str and import_path) or (not import_str and not import_path):
|
||||||
stderr(
|
stderr(
|
||||||
'[X] You should pass either an import path as an argument, '
|
'[X] You should pass an import path or a page url as an argument\n',
|
||||||
'or pass a list of links via stdin, but not both.\n',
|
|
||||||
color='red',
|
color='red',
|
||||||
)
|
)
|
||||||
raise SystemExit(2)
|
raise SystemExit(2)
|
||||||
|
|
|
@ -31,3 +31,9 @@ def test_add_link(tmp_path, process):
|
||||||
output_html = f.read()
|
output_html = f.read()
|
||||||
assert "Example Domain" in output_html
|
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")
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue