|
1 | 1 | """ Allure reporting integration """ |
2 | | - |
| 2 | +import platform |
3 | 3 | from typing import List |
4 | | -import rich_click as click |
5 | | -from pylenium.scripts.cli_utils import run_process, parse_response |
| 4 | + |
| 5 | +import typer |
| 6 | + |
| 7 | +from pylenium.scripts.cli_utils import parse_response, run_process |
6 | 8 |
|
7 | 9 |
|
8 | 10 | def _install(commands: List[str]): |
9 | 11 | """Command to install allure via the CLI""" |
10 | | - click.echo("\n🛑 It's recommended that you run the above command(s) yourself to see all the output 🛑") |
11 | | - answer = click.prompt("\nWould you like to proceed? (y/n)", default="n") |
| 12 | + typer.secho("\n🛑 It's recommended that you run the above command(s) yourself to see all the output 🛑", fg=typer.colors.BRIGHT_YELLOW) |
| 13 | + answer = typer.prompt("\nWould you like to proceed? (y/n)", default="n") |
12 | 14 | try: |
13 | 15 | if answer == "y": |
14 | 16 | response = run_process(commands) |
15 | 17 | _, err = parse_response(response) |
16 | 18 | if response.returncode != 0: |
17 | | - click.echo(f"😢 Unable to install allure. {err}") |
18 | | - click.echo("Visit allure's docs for more options: https://docs.qameta.io/allure/#_get_started") |
| 19 | + typer.secho(f"😢 Unable to install allure. {err}", fg=typer.colors.BRIGHT_RED) |
| 20 | + typer.secho("Visit allure's docs for more options: https://docs.qameta.io/allure/#_get_started", fg=typer.colors.BRIGHT_CYAN) |
19 | 21 | return |
20 | | - click.echo("✅ allure installed. Try running `pylenium allure check` to verify the installation.") |
| 22 | + typer.secho("✅ allure installed. Try running `pylenium allure check` to verify the installation.", fg=typer.colors.BRIGHT_GREEN) |
21 | 23 | return |
22 | 24 |
|
23 | 25 | if answer == "n" or answer is not None: |
24 | | - click.echo("❌ Command aborted") |
| 26 | + typer.secho("❌ Command aborted") |
25 | 27 | return |
26 | 28 | except FileNotFoundError: |
27 | | - click.echo("One of the commands was not found...") |
28 | | - click.echo("Visit their docs for more info: https://docs.qameta.io/allure/#_get_started") |
| 29 | + typer.secho("One of the commands was not found...", fg=typer.colors.BRIGHT_RED) |
| 30 | + typer.secho("Visit their docs for more info: https://docs.qameta.io/allure/#_get_started", fg=typer.colors.BRIGHT_CYAN) |
29 | 31 |
|
30 | 32 |
|
31 | 33 | def install_for_linux(): |
32 | 34 | """Install allure on a Debian-based Linux machine.""" |
33 | | - click.echo("This command only works for Debian-based Linux and uses sudo:\n") |
34 | | - click.echo(" sudo apt-add-repository ppa:qameta/allure") |
35 | | - click.echo(" sudo apt-get update") |
36 | | - click.echo(" sudo apt-get install allure") |
37 | | - _install([ |
38 | | - "sudo", "apt-add-repository", "ppa:qameta/allure", "-y", |
39 | | - "sudo", "apt-get", "update", "-y", |
40 | | - "sudo", "apt-get", "install", "allure", "-y", |
41 | | - ]) |
| 35 | + typer.secho("This command only works for Debian-based Linux and uses sudo:\n", fg=typer.colors.BRIGHT_YELLOW) |
| 36 | + typer.secho(" sudo apt-add-repository ppa:qameta/allure") |
| 37 | + typer.secho(" sudo apt-get update") |
| 38 | + typer.secho(" sudo apt-get install allure") |
| 39 | + _install( |
| 40 | + [ |
| 41 | + "sudo", |
| 42 | + "apt-add-repository", |
| 43 | + "ppa:qameta/allure", |
| 44 | + "-y", |
| 45 | + "sudo", |
| 46 | + "apt-get", |
| 47 | + "update", |
| 48 | + "-y", |
| 49 | + "sudo", |
| 50 | + "apt-get", |
| 51 | + "install", |
| 52 | + "allure", |
| 53 | + "-y", |
| 54 | + ] |
| 55 | + ) |
42 | 56 |
|
43 | 57 |
|
44 | 58 | def install_for_mac(): |
45 | | - click.echo("This command uses homebrew to do the installation:\n") |
46 | | - click.echo(" brew install allure") |
| 59 | + typer.secho("This command uses homebrew to do the installation:\n", fg=typer.colors.BRIGHT_YELLOW) |
| 60 | + typer.secho(" brew install allure") |
47 | 61 | _install(["brew", "install", "allure"]) |
48 | 62 |
|
49 | 63 |
|
50 | 64 | def install_for_windows(): |
51 | | - click.echo("This command uses scoop to do the installation:\n") |
52 | | - click.echo(" scoop install allure") |
| 65 | + typer.secho("This command uses scoop to do the installation:\n", fg=typer.colors.BRIGHT_YELLOW) |
| 66 | + typer.secho(" scoop install allure") |
53 | 67 | _install(["scoop", "install", "allure"]) |
| 68 | + |
| 69 | + |
| 70 | +app = typer.Typer() |
| 71 | + |
| 72 | + |
| 73 | +@app.command() |
| 74 | +def check(): |
| 75 | + """Check if the allure CLI is installed on the current machine.""" |
| 76 | + typer.secho("\n$ allure --version") |
| 77 | + err_message = "\n❌ allure is not installed or not added to the PATH. Visit https://docs.qameta.io/allure/#_get_started" |
| 78 | + try: |
| 79 | + response = run_process(["allure", "--version"]) |
| 80 | + out, err = parse_response(response) |
| 81 | + if response.returncode != 0: |
| 82 | + typer.secho(err_message, fg=typer.colors.BRIGHT_RED) |
| 83 | + typer.secho(err, fg=typer.colors.BRIGHT_RED) |
| 84 | + return |
| 85 | + typer.secho(f"\n✅ allure is installed with version: {out}", fg=typer.colors.BRIGHT_GREEN) |
| 86 | + except FileNotFoundError: |
| 87 | + typer.secho(err_message) |
| 88 | + |
| 89 | + |
| 90 | +@app.command() |
| 91 | +def install(): |
| 92 | + """Install the allure CLI to the current machine.""" |
| 93 | + typer.secho( |
| 94 | + "\n💡 For more installation options and details, please visit allure's docs: https://docs.qameta.io/allure/#_get_started", fg=typer.colors.BRIGHT_CYAN |
| 95 | + ) |
| 96 | + operating_system = platform.system() |
| 97 | + if operating_system.upper() == "LINUX": |
| 98 | + install_for_linux() |
| 99 | + return |
| 100 | + |
| 101 | + if operating_system.upper() == "DARWIN": |
| 102 | + install_for_mac() |
| 103 | + return |
| 104 | + |
| 105 | + if operating_system.upper() == "WINDOWS": |
| 106 | + install_for_windows() |
| 107 | + return |
| 108 | + |
| 109 | + |
| 110 | +@app.command() |
| 111 | +def serve(folder: str = typer.Option("allure-report", "--folder", "-f", help="The folder path to the allure report")): |
| 112 | + """Start the allure server and serve the allure report given its folder path.""" |
| 113 | + typer.secho(f"\n$ allure serve {folder}") |
| 114 | + typer.secho("Press <Ctrl+C> to exit", fg=typer.colors.BRIGHT_CYAN) |
| 115 | + try: |
| 116 | + response = run_process(["allure", "serve", folder]) |
| 117 | + _, err = parse_response(response) |
| 118 | + if response.returncode != 0: |
| 119 | + typer.secho(f"\n❌ Unable to serve allure report. Check that the folder path is valid. {err}", fg=typer.colors.BRIGHT_RED) |
| 120 | + except FileNotFoundError: |
| 121 | + typer.secho("\n❌ allure is not installed or not added to the PATH. Visit https://docs.qameta.io/allure/#_get_started", fg=typer.colors.BRIGHT_RED) |
| 122 | + |
| 123 | + |
| 124 | +if __name__ == "__main__": |
| 125 | + app() |
0 commit comments