|
1 | | -import argparse |
2 | | -from pathlib import Path |
3 | | - |
4 | | -from pyfiglet import Figlet |
5 | | -from rich.console import Console |
6 | | -from colorama import Fore, Style |
7 | | - |
8 | | -from scraper.chrome_scraper import ChromePageScraper |
9 | | - |
10 | | - |
11 | | -def create_cli(): |
12 | | - # Initialize ArgumentParser |
13 | | - parser = argparse.ArgumentParser(prog="sstf", description="SSTF Command Line Tool") |
14 | | - |
15 | | - # Add the 'get' subcommand |
16 | | - subparsers = parser.add_subparsers(dest="command") |
17 | | - |
18 | | - # Add subcommand for 'get' |
19 | | - get_parser = subparsers.add_parser("get", help="Download and manage Chromedriver") |
20 | | - get_subparsers = get_parser.add_subparsers(dest="subcommand") |
21 | | - |
22 | | - # Add subcommand for 'chromedriver' |
23 | | - chromedriver_parser = get_subparsers.add_parser("chromedriver", |
24 | | - help="Download chromedriver for a specified version and platform") |
25 | | - chromedriver_parser.add_argument('--milestone', type=str, |
26 | | - help=f"{Fore.CYAN}Chromium milestone version (e.g., 131).{Style.RESET_ALL}") |
27 | | - chromedriver_parser.add_argument('--version', type=str, |
28 | | - help=f"{Fore.CYAN}Chromium browser version.{Style.RESET_ALL}") |
29 | | - chromedriver_parser.add_argument('--platform', type=str, choices=["windows", "mac", "linux"], |
30 | | - help=f"{Fore.CYAN}Operating system platform.{Style.RESET_ALL}") |
31 | | - chromedriver_parser.add_argument('--output-dir', type=str, default=None, |
32 | | - help=f"{Fore.CYAN}Directory to save the downloaded Chromedriver.{Style.RESET_ALL}") |
33 | | - chromedriver_parser.add_argument('--extract', action='store_true', |
34 | | - help=f"{Fore.CYAN}Extract the Chromedriver after download.{Style.RESET_ALL}") |
35 | | - |
36 | | - # Parse arguments |
37 | | - args = parser.parse_args() |
38 | | - |
39 | | - # Handle 'get chromedriver' logic |
40 | | - if args.command == "get" and args.subcommand == "chromedriver": |
41 | | - console = Console() |
42 | | - |
43 | | - # ASCII Art Header with Figlet (using Rich) |
44 | | - fig = Figlet(font="slant") # You can use different fonts like 'slant', 'block', etc. |
45 | | - console.print(fig.renderText("Chromedriver Download"), style="bold green") |
46 | | - |
47 | | - # Run the actual logic for downloading chromedriver |
48 | | - ChromePageScraper.get_chromedriver( |
49 | | - platform=args.platform, |
50 | | - version=args.version, |
51 | | - milestone=args.milestone, |
52 | | - d_dir=Path(args.output_dir) if args.output_dir else None, |
53 | | - is_extracted=args.extract |
54 | | - ) |
55 | | - |
56 | | - |
57 | | -if __name__ == "__main__": |
58 | | - create_cli() |
| 1 | +@click.command() |
| 2 | +@click.option("--platform", default=None, help="OS and architecture (e.g., 'win64', 'mac64')") |
| 3 | +@click.option("--version", default=None, help="The version of Chrome (e.g., '89.0.4389.82')") |
| 4 | +@click.option("--milestone", default=None, help="Milestone version (e.g., '129')") |
| 5 | +@click.option("--dir", default=None, type=pathlib.Path, help="Directory to save the chromedriver") |
| 6 | +@click.option("--extract", is_flag=True, help="Extract the chromedriver after downloading") |
| 7 | +def cli(platform, version, milestone, dir, extract): |
| 8 | + """ |
| 9 | + CLI command to fetch the latest Chrome driver |
| 10 | + """ |
| 11 | + print(f"Fetching ChromeDriver for platform: {platform}, version: {version}, milestone: {milestone}") |
| 12 | + ChromePageScraper.get_chromedriver(platform=platform, version=version, milestone=milestone, d_dir=dir, is_extracted=extract) |
0 commit comments