diff --git a/docs/multi.md b/docs/multi.md index 6e365f7..d7071e1 100644 --- a/docs/multi.md +++ b/docs/multi.md @@ -115,7 +115,15 @@ If you need to run a server for the duration of the `shot-scraper multi` session ```yaml - server: python -m http.server 8000 ``` -You can now take screenshots of `http://localhost:8000/` and any other URLs that are relative to that server: +The `server:` key also accepts a list of arguments: +```yaml +- server: + - python + - -m + - http.server + - 8000 +``` +With that server configured, you can now take screenshots of `http://localhost:8000/` and any other URLs hosted by that server: ```yaml - output: index.png url: http://localhost:8000/ diff --git a/shot_scraper/cli.py b/shot_scraper/cli.py index 103851d..0581957 100644 --- a/shot_scraper/cli.py +++ b/shot_scraper/cli.py @@ -556,9 +556,13 @@ def multi( subprocess.run([sys.executable, "-c", shot["python"]]) if "server" in shot: # Start that subprocess and remember the pid - server_processes.append( - subprocess.Popen(shot["server"], shell=True) - ) + server = shot["server"] + if isinstance(server, str): + server_processes.append(subprocess.Popen(server, shell=True)) + elif isinstance(server, list): + server_processes.append(subprocess.Popen(map(str, server))) + else: + raise click.ClickException("server: must be a string or list") time.sleep(1) if "url" in shot: try: diff --git a/tests/test_shot_scraper.py b/tests/test_shot_scraper.py index 9c67f61..30470ce 100644 --- a/tests/test_shot_scraper.py +++ b/tests/test_shot_scraper.py @@ -19,6 +19,16 @@ def test_version(): output: output.png """.strip() +SERVER_YAML2 = """ +- server: + - python + - -m + - http.server + - 9023 +- url: http://localhost:9023/ + output: output.png +""".strip() + COMMANDS_YAML = """ - sh: echo "hello world" > index.html - sh: @@ -30,10 +40,11 @@ def test_version(): """ -def test_multi_server(): +@pytest.mark.parametrize("yaml", (SERVER_YAML, SERVER_YAML2)) +def test_multi_server(yaml): runner = CliRunner() with runner.isolated_filesystem(): - open("server.yaml", "w").write(SERVER_YAML) + open("server.yaml", "w").write(yaml) result = runner.invoke(cli, ["multi", "server.yaml"]) assert result.exit_code == 0, result.output assert pathlib.Path("output.png").exists()