|
1 | 1 | import sys |
| 2 | +from argparse import ArgumentParser |
| 3 | +from importlib import import_module, metadata |
2 | 4 | from rich import print |
3 | 5 | from bugscanx import clear_screen, banner, text_ascii |
4 | 6 |
|
|
19 | 21 |
|
20 | 22 | def display_menu(): |
21 | 23 | banner() |
22 | | - for key, (desc, color) in MENU_OPTIONS.items(): |
23 | | - padding = ' ' if len(key) == 1 else '' |
24 | | - print(f"[{color}] [{key}]{padding} {desc}") |
| 24 | + print("\n".join(f"[{color}] [{k}]{' ' if len(k)==1 else ''} {desc}" |
| 25 | + for k, (desc, color) in MENU_OPTIONS.items())) |
25 | 26 |
|
26 | | -def run_menu_option(choice): |
| 27 | +def run_option(choice): |
27 | 28 | if choice == '12': |
28 | 29 | return False |
| 30 | + if choice not in MENU_OPTIONS: |
| 31 | + return True |
29 | 32 |
|
30 | 33 | clear_screen() |
31 | 34 | text_ascii(MENU_OPTIONS[choice][0], color="bold magenta") |
32 | 35 |
|
33 | 36 | try: |
34 | | - module = __import__('bugscanx.entrypoints.runner', fromlist=[f'run_{choice}']) |
35 | | - getattr(module, f'run_{choice}')() |
| 37 | + getattr(import_module('bugscanx.entrypoints.runner'), f'run_{choice}')() |
| 38 | + print("\n[yellow] Press Enter to continue...", end="") |
36 | 39 | except KeyboardInterrupt: |
37 | 40 | print("\n[yellow] Operation cancelled by user.") |
38 | | - |
39 | | - print("\n[yellow] Press Enter to continue...", end="") |
40 | | - input() |
41 | 41 | return True |
42 | 42 |
|
43 | 43 | def main(): |
| 44 | + parser = ArgumentParser() |
| 45 | + parser.add_argument('-v', '--version', action='store_true') |
| 46 | + parser.add_argument('-u', '--update', action='store_true') |
| 47 | + parser.add_argument('option', nargs='?') |
| 48 | + args = parser.parse_args() |
| 49 | + |
| 50 | + if args.version: |
| 51 | + print(f"[bold cyan]BugScanX version {metadata.version('bugscan-x')}[/bold cyan]") |
| 52 | + return |
| 53 | + if args.update: |
| 54 | + return run_option('11') |
| 55 | + if args.option: |
| 56 | + return 0 if run_option(args.option) else 1 |
| 57 | + |
44 | 58 | try: |
45 | 59 | while True: |
46 | 60 | display_menu() |
47 | | - choice = input("\n\033[36m [-] Your Choice: \033[0m") |
48 | | - |
49 | | - if choice not in MENU_OPTIONS: |
50 | | - continue |
51 | | - |
52 | | - if not run_menu_option(choice): |
| 61 | + if not run_option(input("\n\033[36m [-] Your Choice: \033[0m")): |
53 | 62 | break |
54 | | - |
55 | 63 | except KeyboardInterrupt: |
56 | | - sys.exit() |
| 64 | + sys.exit(0) |
0 commit comments