|
| 1 | +import { machines } from "../../../api/machines.ts"; |
| 2 | +import { fields } from "../../../flags.ts"; |
1 | 3 | import { asserts } from "../../../lib/asserts.ts"; |
2 | | -import { loading } from "../../../lib/loading.ts"; |
3 | | -import { args, command, flag, flags, z } from "../../../zcli.ts"; |
4 | 4 | import { dataTable } from "../../../lib/data-table.ts"; |
5 | | -import { fields } from "../../../flags.ts"; |
| 5 | +import { loading } from "../../../lib/loading.ts"; |
6 | 6 | import { pickJson } from "../../../lib/pick-json.ts"; |
7 | | -import { machines } from "../../../api/machines.ts"; |
| 7 | +import { select } from "../../../prompts/select.ts"; |
| 8 | +import { args, command, flag, flags, z } from "../../../zcli.ts"; |
8 | 9 | import { |
9 | 10 | MachineAutoSnapshotFrequencySchema, |
10 | 11 | MachinePublicIpTypeSchema, |
11 | 12 | MachineRestorePointFrequencySchema, |
12 | 13 | } from "../schemas.ts"; |
13 | | -import { input } from "../../../prompts/input.ts"; |
14 | 14 |
|
15 | 15 | /** |
16 | 16 | * This variable is automatically generated by `zcli add`. Do not remove this |
@@ -84,10 +84,24 @@ export const update = command("update", { |
84 | 84 | async function* ({ args, flags }) { |
85 | 85 | let [id] = args; |
86 | 86 | if (!id) { |
87 | | - id = await input("ID:", { |
88 | | - filter: (v) => !!v.sequence.match(/[a-zA-Z0-9_-]/), |
89 | | - }); |
90 | | - asserts(id, "A machine ID is required"); |
| 87 | + const existingMachines = await loading(machines.list({ limit: 50 })); |
| 88 | + asserts(existingMachines.ok, existingMachines); |
| 89 | + |
| 90 | + const selected = await select( |
| 91 | + "Select a machine:", |
| 92 | + existingMachines.data.items, |
| 93 | + { |
| 94 | + filter(input, option) { |
| 95 | + return option.name.toLowerCase().startsWith(input); |
| 96 | + }, |
| 97 | + renderOption(option, isSelected) { |
| 98 | + return `${isSelected ? ">" : " "} ${option.name}`; |
| 99 | + }, |
| 100 | + }, |
| 101 | + ); |
| 102 | + |
| 103 | + asserts(selected, "No machine selected."); |
| 104 | + id = selected.id; |
91 | 105 | } |
92 | 106 | const parsedPublicIpType = MachinePublicIpTypeSchema.safeParse( |
93 | 107 | flags["public-ip-type"], |
|
0 commit comments