(args: argparse.Namespace)
| 56 | |
| 57 | |
| 58 | def run(args: argparse.Namespace) -> None: |
| 59 | # Resolve the machine config name eagerly so it can be shown below, unless |
| 60 | # the user supplied a bare instance type instead. |
| 61 | machine = args.machine |
| 62 | if machine is None and args.instance_type is None: |
| 63 | machine = pick_machine() |
| 64 | label = machine or args.instance_type |
| 65 | |
| 66 | descs = load_machine_descs( |
| 67 | machine, |
| 68 | instance_type=args.instance_type, |
| 69 | size_gb=args.size_gb, |
| 70 | ) |
| 71 | |
| 72 | if len(descs) != 1: |
| 73 | raise RuntimeError( |
| 74 | f"'claude' expects a single-machine config, got {len(descs)} machines" |
| 75 | ) |
| 76 | |
| 77 | check_required_vars() |
| 78 | |
| 79 | # Find existing instances |
| 80 | existing = list_all_instances() |
| 81 | active = [ |
| 82 | i for i in existing if i.state and i.state["Name"] in ("running", "pending") |
| 83 | ] |
| 84 | |
| 85 | if active: |
| 86 | print_instances(active, numbered=True) |
| 87 | print(f" {len(active) + 1}) Create new instance ({label})") |
| 88 | while True: |
| 89 | choice = input("Select an instance or create new [#]: ").strip() |
| 90 | try: |
| 91 | idx = int(choice) |
| 92 | if 1 <= idx <= len(active): |
| 93 | instance = active[idx - 1] |
| 94 | break |
| 95 | if idx == len(active) + 1: |
| 96 | instance = None |
| 97 | break |
| 98 | except ValueError: |
| 99 | pass |
| 100 | print(f"Invalid choice. Enter a number 1-{len(active) + 1}.") |
| 101 | else: |
| 102 | instance = None |
| 103 | |
| 104 | if instance is None: |
| 105 | say(f"Creating from {label}...") |
| 106 | max_age = datetime.timedelta(days=args.max_age_days) |
| 107 | extra_tags = {"LaunchedBy": whoami()} |
| 108 | instances = launch_cluster( |
| 109 | descs, |
| 110 | extra_tags=extra_tags, |
| 111 | delete_after=datetime.datetime.now(datetime.timezone.utc) + max_age, |
| 112 | ) |
| 113 | |
| 114 | print("Launched:") |
| 115 | print_instances(instances, "table") |
nothing calls this directly
no test coverage detected