From de64c6d4d59b7d213530cb5085a96b3380ecc5a6 Mon Sep 17 00:00:00 2001 From: sBubshait Date: Tue, 5 Aug 2025 14:13:45 +0300 Subject: [PATCH] feat: dont list datasets if there are many --- snapshots/snapshot.py | 47 +++++++++++++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 13 deletions(-) diff --git a/snapshots/snapshot.py b/snapshots/snapshot.py index 97bc837..50a317e 100644 --- a/snapshots/snapshot.py +++ b/snapshots/snapshot.py @@ -159,19 +159,40 @@ class PDGSnapshot: print(f"{Colors.RED}✗ No ZFS datasets found{Colors.ENDC}") return None - print(f"\n{Colors.BOLD}Available ZFS Datasets:{Colors.ENDC}") - for i, dataset in enumerate(datasets, 1): - print(f"{Colors.CYAN}{i:2d}.{Colors.ENDC} {dataset}") - - while True: - try: - choice = input(f"\n{Colors.BOLD}Select dataset (1-{len(datasets)}): {Colors.ENDC}") - idx = int(choice) - 1 - if 0 <= idx < len(datasets): - return datasets[idx] - print(f"{Colors.RED}Invalid selection{Colors.ENDC}") - except (ValueError, KeyboardInterrupt): - return None + # If too many datasets, ask for manual input + if len(datasets) > 100: + print(f"\n{Colors.YELLOW}Found {len(datasets)} datasets - too many to list{Colors.ENDC}") + print(f"{Colors.DIM}Tip: Use 'zfs list' to see all available datasets{Colors.ENDC}") + + while True: + dataset = input(f"\n{Colors.BOLD}Enter dataset name: {Colors.ENDC}").strip() + if not dataset: + return None + + # Check if dataset exists + success, _ = self.run_command(f"zfs list {dataset}") + if success: + return dataset + else: + print(f"{Colors.RED}✗ Dataset '{dataset}' not found{Colors.ENDC}") + retry = input(f"{Colors.DIM}Try again? (y/n): {Colors.ENDC}").lower() + if retry != 'y': + return None + else: + # Show numbered list for reasonable amount of datasets + print(f"\n{Colors.BOLD}Available ZFS Datasets:{Colors.ENDC}") + for i, dataset in enumerate(datasets, 1): + print(f"{Colors.CYAN}{i:2d}.{Colors.ENDC} {dataset}") + + while True: + try: + choice = input(f"\n{Colors.BOLD}Select dataset (1-{len(datasets)}): {Colors.ENDC}") + idx = int(choice) - 1 + if 0 <= idx < len(datasets): + return datasets[idx] + print(f"{Colors.RED}Invalid selection{Colors.ENDC}") + except (ValueError, KeyboardInterrupt): + return None def select_schedule(self) -> Optional[str]: """Interactive schedule selection"""