feat: list command fails when --index is used without --json or --html

This commit is contained in:
Cristian 2020-08-19 13:14:04 -05:00 committed by Cristian Vargas
parent 885ff50449
commit a77d6dc235
2 changed files with 12 additions and 1 deletions

View file

@ -23,7 +23,7 @@ from ..index import (
get_corrupted_folders,
get_unrecognized_folders,
)
from ..logging_util import SmartFormatter, accept_stdin
from ..logging_util import SmartFormatter, accept_stdin, stderr
@docstring(list_all.__doc__)
@ -112,6 +112,13 @@ def main(args: Optional[List[str]]=None, stdin: Optional[IO]=None, pwd: Optional
command = parser.parse_args(args or ())
filter_patterns_str = accept_stdin(stdin)
if command.index and not (command.json or command.html):
stderr(
'[X] --index can only be used with --json or --html options.\n',
color='red',
)
raise SystemExit(2)
matching_folders = list_all(
filter_patterns_str=filter_patterns_str,
filter_patterns=command.filter_patterns,

View file

@ -32,3 +32,7 @@ def test_list_html_index(process, disable_extractors_dict):
output_html = list_process.stdout.decode("utf-8")
assert "<footer>" in output_html
assert "http://127.0.0.1:8080/static/example.com.html" in output_html
def test_list_index_with_wrong_flags(process):
list_process = subprocess.run(["archivebox", "list", "--index"], capture_output=True)
assert "--index can only be used with --json or --html options." in list_process.stderr.decode("utf-8")